fix: regex change for username

This commit is contained in:
Jannat Patel
2021-09-19 19:15:45 +05:30
parent 0ab708396a
commit e245af57a8
2 changed files with 8 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ class CustomUser(User):
else:
underscore_condition = ''
regex = re.compile('[@!#$%^&*()<>?/\|}{~:-]')
if self.is_new():
if not self.username:
self.username = self.get_username_from_first_name()
@@ -25,7 +27,7 @@ class CustomUser(User):
if self.username.find(" "):
self.username.replace(" ", "")
if not re.match("^[A-Za-z0-9_]*$", self.username) or underscore_condition:
if regex.search(self.username) or underscore_condition:
self.username = self.remove_illegal_characters()
if len(self.username) < 4:
@@ -38,7 +40,7 @@ class CustomUser(User):
if not self.username:
frappe.throw(_("Username already exists."))
if not re.match("^[A-Za-z0-9_]*$", self.username):
if regex.search(self.username):
frappe.throw(_("Username can only contain alphabets, numbers and underscore."))
if underscore_condition: