Validation pattern for nickname on login screen

main
Bob Mottram 2021-07-29 13:18:12 +01:00
parent 6d6af419fa
commit f6ee975236
2 changed files with 39 additions and 20 deletions

View File

@ -1567,10 +1567,8 @@ def isValidLanguage(text: str) -> bool:
return False
def _isReservedName(nickname: str) -> bool:
"""Is the given nickname reserved for some special function?
"""
reservedNames = ('inbox', 'dm', 'outbox', 'following',
def _getReservedWords() -> str:
return ('inbox', 'dm', 'outbox', 'following',
'public', 'followers', 'category',
'channel', 'calendar',
'tlreplies', 'tlmedia', 'tlblogs',
@ -1588,6 +1586,25 @@ def _isReservedName(nickname: str) -> bool:
'ignores', 'linksmobile', 'newswiremobile',
'minimal', 'search', 'eventdelete',
'searchemoji', 'catalog')
def getNicknameValidationPattern() -> str:
"""Returns a html text input validation pattern for nickname
"""
reservedNames = _getReservedWords()
pattern = ''
for word in reservedNames:
if pattern:
pattern += '|' + word
else:
pattern = '[^(' + word
return pattern + ')]'
def _isReservedName(nickname: str) -> bool:
"""Is the given nickname reserved for some special function?
"""
reservedNames = _getReservedWords()
if nickname in reservedNames:
return True
return False

View File

@ -12,6 +12,7 @@ import time
from shutil import copyfile
from utils import getConfigParam
from utils import noOfAccounts
from utils import getNicknameValidationPattern
from webapp_utils import htmlHeaderWithWebsiteMarkup
from webapp_utils import htmlFooter
from webapp_utils import htmlKeyboardNavigation
@ -152,6 +153,7 @@ def htmlLogin(cssCache: {}, translate: {},
htmlHeaderWithWebsiteMarkup(cssFilename, instanceTitle,
httpPrefix, domain,
systemLanguage)
nicknamePattern = getNicknameValidationPattern()
instanceTitle = getConfigParam(baseDir, 'instanceTitle')
loginForm += \
'<br>\n' + \
@ -167,8 +169,8 @@ def htmlLogin(cssCache: {}, translate: {},
' <label for="nickname"><b>' + \
translate['Nickname'] + '</b></label>\n' + \
' <input type="text" ' + autocompleteStr + ' placeholder="' + \
translate['Enter Nickname'] + \
'" name="username" required autofocus>\n' + \
translate['Enter Nickname'] + '" name="username" ' + \
'pattern="' + nicknamePattern + '" required autofocus>\n' + \
'\n' + \
' <label for="password"><b>' + \
translate['Password'] + '</b></label>\n' + \