예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 def refresh_key(self):
     session = DBSession()
     self.key = random_str(32)
     self.key_time = int(time.time())
     session.add(self)
     session.commit()
     session.close()
예제 #4
0
 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()
예제 #5
0
 def refresh_key(self):
     session = DBSession()
     self.key = random_str(32)
     self.key_time = int(time.time())
     session.add(self)
     session.commit()
     session.close()
예제 #6
0
 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()
예제 #7
0
 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
예제 #8
0
 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
예제 #9
0
 def exist(cls, username):
     session = DBSession()
     r = session.query(cls).filter(cls.username==username).count() > 0
     session.close()
     return r
예제 #10
0
 def count(cls):
     session = DBSession()
     r = session.query(cls).filter(cls.level>0).count()
     return r
예제 #11
0
 def get_by_username(cls, username):
     session = DBSession()
     r = session.query(cls).filter(cls.username==username).first()
     session.close()
     return r
예제 #12
0
 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()
예제 #13
0
 def count(cls):
     session = DBSession()
     r = session.query(cls).filter(cls.level > 0).count()
     return r
예제 #14
0
 def get_by_username(cls, username):
     session = DBSession()
     r = session.query(cls).filter(cls.username == username).first()
     session.close()
     return r
예제 #15
0
 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()
예제 #16
0
 def exist(cls, username):
     session = DBSession()
     r = session.query(cls).filter(cls.username == username).count() > 0
     session.close()
     return r