From 671df67723abfe723fa51400f705e71d7e9332e5 Mon Sep 17 00:00:00 2001 From: mrlan Date: Thu, 10 Nov 2022 19:03:59 +0800 Subject: [PATCH] Bug487-WuYuhan-Refactor (#58) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将所有用于用户名验证的逻辑放入到 `UserName` 类中。 Hui Co-authored-by: Lan Hui <1348141770@qq.com> Reviewed-on: http://121.4.94.30:3000/mrlan/EnglishPal/pulls/58 Co-authored-by: mrlan Co-committed-by: mrlan --- app/Login.py | 11 ++++------- app/account_service.py | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Login.py b/app/Login.py index 64612bc..1ada0af 100644 --- a/app/Login.py +++ b/app/Login.py @@ -98,6 +98,9 @@ class UserName: for c in self.username: # a user name must not include special characters, except non-leading periods or underscores if c in string.punctuation and c is not '.' and c is not '_': return f'{c} is not allowed in the user name.' + if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del']: + return 'You used a restricted word as your user name. Please come up with a better one.' + return 'OK' @@ -106,11 +109,5 @@ class WarningMessage: self.s = s def __str__(self): - result = UserName(self.s).validate() - if result != 'OK': - return result + return UserName(self.s).validate() - if self.s in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del']: - return 'You used a restricted word as the user name. Please come up with a better one.' - - return 'OK' diff --git a/app/account_service.py b/app/account_service.py index 4aafe67..09439d5 100644 --- a/app/account_service.py +++ b/app/account_service.py @@ -1,5 +1,6 @@ from flask import * -from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, UserName, WarningMessage +from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage + # 初始化蓝图 accountService = Blueprint("accountService", __name__)