diff --git a/utils.py b/utils.py
index 1d716ade5..ae3ea46af 100644
--- a/utils.py
+++ b/utils.py
@@ -1567,27 +1567,44 @@ def isValidLanguage(text: str) -> bool:
return False
+def _getReservedWords() -> str:
+ return ('inbox', 'dm', 'outbox', 'following',
+ 'public', 'followers', 'category',
+ 'channel', 'calendar',
+ 'tlreplies', 'tlmedia', 'tlblogs',
+ 'tlblogs', 'tlfeatures',
+ 'moderation', 'moderationaction',
+ 'activity', 'undo', 'pinned',
+ 'reply', 'replies', 'question', 'like',
+ 'likes', 'users', 'statuses', 'tags',
+ 'accounts', 'headers',
+ 'channels', 'profile', 'u', 'c',
+ 'updates', 'repeat', 'announce',
+ 'shares', 'fonts', 'icons', 'avatars',
+ 'welcome', 'helpimages',
+ 'bookmark', 'bookmarks', 'tlbookmarks',
+ '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 = ('inbox', 'dm', 'outbox', 'following',
- 'public', 'followers', 'category',
- 'channel', 'calendar',
- 'tlreplies', 'tlmedia', 'tlblogs',
- 'tlblogs', 'tlfeatures',
- 'moderation', 'moderationaction',
- 'activity', 'undo', 'pinned',
- 'reply', 'replies', 'question', 'like',
- 'likes', 'users', 'statuses', 'tags',
- 'accounts', 'headers',
- 'channels', 'profile', 'u', 'c',
- 'updates', 'repeat', 'announce',
- 'shares', 'fonts', 'icons', 'avatars',
- 'welcome', 'helpimages',
- 'bookmark', 'bookmarks', 'tlbookmarks',
- 'ignores', 'linksmobile', 'newswiremobile',
- 'minimal', 'search', 'eventdelete',
- 'searchemoji', 'catalog')
+ reservedNames = _getReservedWords()
if nickname in reservedNames:
return True
return False
diff --git a/webapp_login.py b/webapp_login.py
index 585499631..37f23f79c 100644
--- a/webapp_login.py
+++ b/webapp_login.py
@@ -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 += \
'
\n' + \
@@ -167,8 +169,8 @@ def htmlLogin(cssCache: {}, translate: {},
' \n' + \
' \n' + \
+ translate['Enter Nickname'] + '" name="username" ' + \
+ 'pattern="' + nicknamePattern + '" required autofocus>\n' + \
'\n' + \
' \n' + \