forked from mrlan/EnglishPal
				
			Move all username validation logic to class UserName
							parent
							
								
									702205940c
								
							
						
					
					
						commit
						02efc30dcf
					
				
							
								
								
									
										11
									
								
								app/Login.py
								
								
								
								
							
							
						
						
									
										11
									
								
								app/Login.py
								
								
								
								
							| 
						 | 
				
			
			@ -98,6 +98,9 @@ class UserName:
 | 
			
		|||
        for c in self.username: # a user name not include special characters
 | 
			
		||||
            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 username.  Please come up with a better one.'
 | 
			
		||||
 | 
			
		||||
        return 'OK'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
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
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
# 初始化蓝图
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue