Move all username validation logic to class UserName
						commit
						345f751c16
					
				| 
						 | 
					@ -93,9 +93,9 @@ class UserName:
 | 
				
			||||||
            return f'{self.username} is too long.  The user name cannot exceed 20 characters.'
 | 
					            return f'{self.username} is too long.  The user name cannot exceed 20 characters.'
 | 
				
			||||||
        if self.username.startswith('.'): # a user name must not start with a dot
 | 
					        if self.username.startswith('.'): # a user name must not start with a dot
 | 
				
			||||||
            return 'Period (.) is not allowed as the first letter in the user name.'
 | 
					            return 'Period (.) is not allowed as the first letter in the user name.'
 | 
				
			||||||
        if ' ' in self.username: # a user must not include a whitespace
 | 
					        if ' ' in self.username: # a user name must not include a whitespace
 | 
				
			||||||
            return 'Whitespace is not allowed in the user name.'
 | 
					            return 'Whitespace is not allowed in the user name.'
 | 
				
			||||||
        for c in self.username: # a user name not include special characters
 | 
					        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']:
 | 
					        if self.username in ['signup', 'login', 'logout', 'reset', 'mark', 'back', 'unfamiliar', 'familiar', 'del']:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
from flask import *
 | 
					from flask import *
 | 
				
			||||||
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
 | 
					from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
 | 
				
			||||||
import re
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 初始化蓝图
 | 
					# 初始化蓝图
 | 
				
			||||||
accountService = Blueprint("accountService", __name__)
 | 
					accountService = Blueprint("accountService", __name__)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue