Esempio n. 1
0
 def add(self, user, pwd, email):
     self._print('add starts, add->user=%s, pwd=%s, email=%s' %
                 (str(user), str(pwd), str(email)))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user': user}, {'uid': 1, '_id': 0})
         if res:
             show_error(
                 self,
                 'failed to register, invalid user, the user has been registered'
             )
             return
         pubkey, privkey = self._generate_key()
         info = coll.save({
             'user': user,
             'password': pwd,
             'email': email,
             'uid': uid,
             'pubkey': pubkey,
             'privkey': privkey
         })
         if not info:
             show_error(self,
                        'failed to register, failed to save user info')
             return
         if SHOW_TIME:
             self._print('add, time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
         return uid
     except:
         show_error(self,
                    'failed to register, invalid register information')
Esempio n. 2
0
File: user.py Progetto: tx626/dpm
 def get_password(self, user):
     self._print('get_password->user=%s' % str(user))
     try:
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user': user}, {'password':1, '_id':0})
         if res:
             return res.get('password')
     except:
         show_error(self, 'failed to get password')
Esempio n. 3
0
 def get_password(self, user):
     self._print('get_password->user=%s' % str(user))
     try:
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user': user}, {'password': 1, '_id': 0})
         if res:
             return res.get('password')
     except:
         show_error(self, 'failed to get password')
Esempio n. 4
0
 def remove(self, user):
     self._print('remove starts')
     try:
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user': user}, {'uid': 1})
         if res:
             coll.remove(res['_id'])
             return True
     except:
         show_error(self, 'failed to get public key')
Esempio n. 5
0
File: user.py Progetto: tx626/dpm
 def remove(self, user):
     self._print('remove starts')
     try:
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user':user}, {'uid':1})
         if res:
             coll.remove(res['_id'])
             return True
     except:
         show_error(self, 'failed to get public key')
Esempio n. 6
0
 def get_public_key(self, user):
     self._print('get_public_key->user=%s' % str(user))
     try:
         uid = get_uid(user)
         key = self._public_keys.get(uid)
         if not key:
             coll = self._get_collection(uid, TABLE_USERINFO)
             res = coll.find_one({'user': user}, {'pubkey': 1, '_id': 0})
             key = res.get('pubkey')
             if key:
                 if len(self._public_keys) >= CACHE_MAX:
                     self._public_keys.popitem()
                 self._public_keys.update({uid: key})
         return (uid, key)
     except:
         show_error(self, 'failed to get public key')
Esempio n. 7
0
File: user.py Progetto: tx626/dpm
 def get_public_key(self, user):
     self._print('get_public_key->user=%s' % str(user))
     try:
         uid = get_uid(user)
         key = self._public_keys.get(uid)
         if not key:
             coll = self._get_collection(uid, TABLE_USERINFO)
             res = coll.find_one({'user': user}, {'pubkey':1, '_id':0})
             key = res.get('pubkey')
             if key:
                 if len(self._public_keys) >= CACHE_MAX:
                     self._public_keys.popitem()
                 self._public_keys.update({uid:key})
         return (uid, key)
     except:
         show_error(self, 'failed to get public key')
Esempio n. 8
0
File: user.py Progetto: tx626/dpm
 def add(self, user, pwd, email):
     self._print('add starts, add->user=%s, pwd=%s, email=%s' % (str(user), str(pwd), str(email)))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         uid = get_uid(user)
         coll = self._get_collection(uid, TABLE_USERINFO)
         res = coll.find_one({'user':user}, {'uid':1, '_id':0})
         if res:
             show_error(self, 'failed to register, invalid user, the user has been registered')
             return
         pubkey, privkey = self._generate_key()
         info = coll.save({'user':user, 'password':pwd, 'email':email, 'uid':uid, 'pubkey':pubkey, 'privkey':privkey})
         if not info:
             show_error(self, 'failed to register, failed to save user info')
             return
         if SHOW_TIME:
             self._print('add, time=%d sec' % (datetime.utcnow() - start_time).seconds)
         return uid
     except:
         show_error(self, 'failed to register, invalid register information')
Esempio n. 9
0
 def _get_lock(self, user):
     uid = get_uid(user)
     return self._locks.get_node(uid)
Esempio n. 10
0
File: manager.py Progetto: tx626/dpm
 def _get_user_backend(self, user):
     ring = HashRing(BACKEND_SERVERS)
     uid = get_uid(user)
     server = ring.get_node(uid)
     return server
Esempio n. 11
0
File: manager.py Progetto: tx626/dpm
 def _get_user_backend(self, user):
     ring = HashRing(BACKEND_SERVERS)
     uid = get_uid(user)
     server = ring.get_node(uid)
     return server
Esempio n. 12
0
File: backend.py Progetto: tx626/dpm
 def _get_lock(self, user):
     uid = get_uid(user)
     return self._locks.get_node(uid)
Esempio n. 13
0
 def _get_user_backend(self, user):
     ring = HashRing(SERVER_BACKEND)
     uid = get_uid(user)
     return ring.get_node(uid)