def reset_pwd(self, uid, old_password, new_password): try: not_empty(uid, old_password, new_password) _id = ObjectId(uid) kwargs = dict(_id=_id, password=hashPassword(old_password)) valid = self.exists(**kwargs) if valid: self.update(uid, password= hashPassword(new_password)) return True, 'OK' else: return False, 'INVALIDED' except ValueError: return False, 'NO_EMPTY'
def reset_pwd(self, uid, old_password, new_password): try: not_empty(uid, old_password, new_password) _id = ObjectId(uid) kwargs = dict(_id=_id, password=hashPassword(old_password)) valid = self.exists(**kwargs) if valid: self.update(uid, password=hashPassword(new_password)) return True, 'OK' else: return False, 'INVALIDED' except ValueError: return False, 'NO_EMPTY'
def reset_pwd(uid, old_password, new_password): try: not_empty(uid, old_password, new_password) _id = ObjectId(uid) kwargs = dict(_id=_id, password=hashPassword(old_password)) valid = m_exists(TName, **kwargs) if valid: Tb().update(kwargs, {'$set': {'password': hashPassword(new_password)}}) return True, 'OK' else: return False, 'INVALIDED' except ValueError: return False, 'NO_EMPTY'
def update(username, password=None, name=None, email=None, group=None, callback=None): ''' 修改用户息 ''' not_empty(username) val = dict(type='update', username=username, password=hashPassword(password), name=name, email=email, groups=group) url = _make_url(val) print url return client.fetch(url, callback=callback)
def add(username, password, name, email=None, group=None, callback=None): ''' 添加一个用户到openfire ''' not_empty(username, password, name) val = dict(type='add', username=username, password=hashPassword(password), name=name, email=email, groups=group) url = _make_url(val) print url return client.fetch(url, callback=callback)
def add(self, username, password, city=None, **kwargs): try: not_empty(username, password) r = self.exists(username=username) if not r: val = dict(username=username, password=hashPassword(password), city=city) _id = self.insert(val,**kwargs) val['_id'] = str(_id) return True, val else: return False, 'EXISTS' except ValueError: return False, 'NO_EMPTY'
def add(username, password, city=None, **kwargs): try: not_empty(username, password) r = m_exists(TName, username=username) if not r: val = dict(username=username, password=hashPassword(password), city=city) val.update(kwargs) _id = Tb().insert(val, saft=True) val['_id'] = str(_id) return True, val else: return False, 'EXISTS' except ValueError: return False, 'NO_EMPTY'
def add(self, username, password, city=None, **kwargs): try: not_empty(username, password) r = self.exists(username=username) if not r: val = dict(username=username, password=hashPassword(password), city=city) _id = self.insert(val, **kwargs) val['_id'] = str(_id) return True, val else: return False, 'EXISTS' except ValueError: return False, 'NO_EMPTY'
def reset_forgotten_password(self, key, new_password): try: not_empty(key, new_password) redis = get_context().get_redis() username = redis.get(key) if not username: return False, 'EXPIRED' existed = self.exists(username=username) if existed: self.update(username,key='username', password=hashPassword(new_password)) return True, 'OK' else: return False, 'NO_EXIST' except ValueError: return False, 'NO_EMPTY'
def reset_forgotten_password(key, new_password): try: not_empty(key, new_password) redis = get_context().get_redis() username = redis.get(key) if not username: return False, 'EXPIRED' existed = m_exists(TName, username=username) if existed: Tb().update(dict(username=username), {'$set': {'password': hashPassword(new_password)}}) return True, 'OK' else: return False, 'NO_EXIST' except ValueError: return False, 'NO_EMPTY'
def login(self, username, password, isadmin=None): try: not_empty(username, password) cond = dict(username=username, password=hashPassword(password)) #cond = dict(username=username, password=password) if isadmin: cond.update(isadmin=isadmin) r = self.exists(**cond) if r: r = mongo_conv(r) return True, r else: return False, 'NO_EXISTED' except ValueError: return False, 'NO_EMPTY' except Exception as e: return False, e.message
def reset_forgotten_password(self, key, new_password): try: not_empty(key, new_password) redis = get_context().get_redis() username = redis.get(key) if not username: return False, 'EXPIRED' existed = self.exists(username=username) if existed: self.update(username, key='username', password=hashPassword(new_password)) return True, 'OK' else: return False, 'NO_EXIST' except ValueError: return False, 'NO_EMPTY'
def login(username, password, isadmin=None): try: not_empty(username, password) cond = dict(username=username, password=hashPassword(password)) if isadmin: cond.update(isadmin=isadmin) r = m_exists(TName, **cond) if r: r = mongo_conv(r) if r['status'] == INIT: return False, 'UNACTIVATED' return True, r else: return False, 'NO_EXISTED' except ValueError: return False, 'NO_EMPTY' except Exception as e: return False, e.message