def auth(cls, username, password): session = DBSession() u = session.query(cls).filter(cls.username==username).first() session.close() if not u: return False password_md5 = md5(password.encode('utf-8')).hexdigest() password_final = md5((password_md5 + u.salt).encode('utf-8')).hexdigest() if u.password == password_final: return u
def auth(cls, username, password): session = DBSession() u = session.query(cls).filter(cls.username == username).first() session.close() if not u: return False password_md5 = md5(password.encode('utf-8')).hexdigest() password_final = md5( (password_md5 + u.salt).encode('utf-8')).hexdigest() if u.password == password_final: return u
def refresh_key(self): session = DBSession() self.key = random_str(32) self.key_time = int(time.time()) session.add(self) session.commit() session.close()
def set_password(self, new_password): salt = random_str() password_md5 = md5(new_password.encode('utf-8')).hexdigest() password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest() session = DBSession() self.salt = salt self.password = password_final session.add(self) session.commit() session.close()
def new(cls, username, password): salt = random_str() password_md5 = md5(password.encode('utf-8')).hexdigest() password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest() level = USER_LEVEL.ADMIN if cls.count() == 0 else USER_LEVEL.NORMAL # 首个用户赋予admin权限 the_time = int(time.time()) session = DBSession() ret = User(username=username, password=password_final,openid=openid , salt=salt, level=level, key=random_str(32), key_time = the_time, ) session.add(ret) session.commit() session.close() return ret
def new(cls, username, password): salt = random_str() password_md5 = md5(password.encode('utf-8')).hexdigest() password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest() level = USER_LEVEL.ADMIN if cls.count( ) == 0 else USER_LEVEL.NORMAL # 首个用户赋予admin权限 the_time = int(time.time()) session = DBSession() ret = User( username=username, password=password_final, openid=openid, salt=salt, level=level, key=random_str(32), key_time=the_time, ) session.add(ret) session.commit() session.close() return ret
def exist(cls, username): session = DBSession() r = session.query(cls).filter(cls.username==username).count() > 0 session.close() return r
def count(cls): session = DBSession() r = session.query(cls).filter(cls.level>0).count() return r
def get_by_username(cls, username): session = DBSession() r = session.query(cls).filter(cls.username==username).first() session.close() return r
def get_by_key(cls, key): session = DBSession() the_key = str(key or b'', 'utf-8') r = session.query(cls).filter(cls.key==the_key).first() session.close()
def count(cls): session = DBSession() r = session.query(cls).filter(cls.level > 0).count() return r
def get_by_username(cls, username): session = DBSession() r = session.query(cls).filter(cls.username == username).first() session.close() return r
def get_by_key(cls, key): session = DBSession() the_key = str(key or b'', 'utf-8') r = session.query(cls).filter(cls.key == the_key).first() session.close()
def exist(cls, username): session = DBSession() r = session.query(cls).filter(cls.username == username).count() > 0 session.close() return r