1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Lan Hui 345f751c16 Move all username validation logic to class UserName 2022-11-10 19:00:25 +08:00
Lan Hui 02efc30dcf Move all username validation logic to class UserName 2022-11-10 18:58:06 +08:00
2 changed files with 6 additions and 8 deletions

View File

@ -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 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 '_': if c in string.punctuation and c is not '.' and c is not '_':
return f'{c} is not allowed in the user name.' 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' return 'OK'
@ -106,11 +109,5 @@ class WarningMessage:
self.s = s self.s = s
def __str__(self): def __str__(self):
result = UserName(self.s).validate() return UserName(self.s).validate()
if result != 'OK':
return result
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'

View File

@ -1,5 +1,6 @@
from flask import * 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__) accountService = Blueprint("accountService", __name__)