Exemplo n.º 1
0
 def new(username,
         password,
         email,
         nickname='',
         avatar=config.default_avatar):
     """
     new user
     :param username:
     :param password:
     :param email:
     :param nickname: optional
     :param avatar: optional
     :return:
     """
     salt = random_str()
     password_md5 = md5(password.encode('utf-8')).hexdigest()
     password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
     level = USER_ROLE.NORMAL
     the_time = int(time.time())
     u = User.create(username=username,
                     nickname=nickname,
                     email=email,
                     avatar=avatar,
                     password=password_final,
                     salt=salt,
                     level=level,
                     key=random_str(32),
                     key_time=the_time)
     u.save()
     p = Profile.create(user=u)
     p.save()
     return u
Exemplo n.º 2
0
    def new(username,
            password,
            email,
            nickname='',
            avatar=config.default_avatar,
            level=USER_ROLE.NORMAL,
            isteacher=''):
        salt = random_str()
        password_md5 = md5(password.encode('utf-8')).hexdigest()
        password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()

        #level = USER_ROLE.NORMAL  # 首个用户赋予admin权限
        print(isteacher)
        if isteacher == 'yes':
            level = USER_ROLE.TEACHER
        the_time = int(time.time())
        u = User.create(username=username,
                        nickname=nickname,
                        email=email,
                        avatar=avatar,
                        password=password_final,
                        salt=salt,
                        level=level,
                        key=random_str(32),
                        key_time=the_time)
        u.save()
        p = Profile.create(user=u)
        p.save()
        return u
Exemplo n.º 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()
Exemplo n.º 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()
     self.salt = salt
     self.password = password_final
     self.save()
Exemplo n.º 5
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()
Exemplo n.º 6
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
Exemplo n.º 7
0
 def refresh_key(self):
     self.key = random_str(32)
     self.key_time = int(time.time())
     self.save()
Exemplo n.º 8
0
 def generate_session_id():
     return random_str(16)
Exemplo n.º 9
0
 def generate_session_id():
     return random_str(16)
Exemplo n.º 10
0
 def refresh_key(self):
     """refresh token"""
     self.key = random_str(32)
     self.key_time = int(time.time())
     self.save()