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')
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')
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')
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')
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')
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')
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')
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')
def _get_lock(self, user): uid = get_uid(user) return self._locks.get_node(uid)
def _get_user_backend(self, user): ring = HashRing(BACKEND_SERVERS) uid = get_uid(user) server = ring.get_node(uid) return server
def _get_user_backend(self, user): ring = HashRing(SERVER_BACKEND) uid = get_uid(user) return ring.get_node(uid)