Beispiel #1
0
    def user_login(self, username: str, password: str) -> UserLoginData:
        user = self._user.query_user_by_username(username)
        if user is None:
            raise UserNotFound('用户未找到')
        current_app.logger.debug(MD5.encode_md5(password))
        if user.password != MD5.encode_md5(password):
            raise PasswordError('用户密码错误')

        return UserLoginData(user.id, user.user_type,
                             Token.create_token(user.id, user.user_type))
Beispiel #2
0
 def create_new_user(self, username, password) -> None:
     if self._re_password.match(password) is None:
         raise PasswordNotSatisfactory('密码需要包含字母与数字, 且最少 6 位')
     user = self._user.query_user_by_username(username)
     if user is not None:
         raise UserHaveExist('用户已存在')
     self._user.add_user(username, MD5.encode_md5(password))
     return
Beispiel #3
0
 def handle_password(self, password):
     if self._re_password.match(password) is None:
         raise PasswordNotSatisfactory('密码需要包含字母与数字, 且最少 6 位')
     self._user.password = MD5.encode_md5(password)