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