cn hizki-larriz

This commit is contained in:
Aitzol 2023-04-04 11:02:56 +02:00
parent 6e24de0621
commit 3a0739b384
7 changed files with 14 additions and 10 deletions

14
app.py
View File

@ -27,7 +27,7 @@ from ldap3 import Server, Connection, ALL
from ldap3 import SIMPLE, SUBTREE, MODIFY_REPLACE, ALL_ATTRIBUTES
from ldap3.core.exceptions import LDAPBindError, LDAPConstraintViolationResult, \
LDAPInvalidCredentialsResult, LDAPUserNameIsMandatoryError, \
LDAPSocketOpenError, LDAPExceptionError
LDAPSocketOpenError, LDAPExceptionError, LDAPAttributeOrValueExistsResult
import logging
from os import getenv, environ, path
from libs import flist, slist
@ -148,7 +148,7 @@ def post_signup():
result = random.choice(flist.firstname)
elif arg == 'surname':
result = random.choice(slist.surname)
return(result.lower())
return(result.capitalize())
def error(msg):
return signup_tpl(alerts=[('error', msg, 'fadeOut')], str=i18n.str)
@ -167,13 +167,13 @@ def post_signup():
firstname = auto_complete('firstname')
isFake = True
else:
firstname = form('firstname').lower()
firstname = form('firstname').title()
if len(form('surname')) == 0:
surname = auto_complete('surname')
isFake = True
else:
surname = form('surname').lower()
surname = form('surname').title()
email = form('email').lower()
if not tools.email_validation(email):
@ -217,16 +217,16 @@ def post_edit_fullname():
if len(form('firstname')) < 3:
return error(i18n.msg[11])
elif not tools.input_validation(form('firstname')):
elif not tools.input_validation(form('firstname'), True):
return error(i18n.msg[4])
if len(form('surname')) < 3:
return error(i18n.msg[12])
elif not tools.input_validation(form('surname')):
elif not tools.input_validation(form('surname'), True):
return error(i18n.msg[5])
try:
edit_fullname(username, old_firstname, old_surname, form('firstname').lower(), form('surname').lower())
edit_fullname(username, old_firstname, old_surname, form('firstname').title(), form('surname').title())
except Error as e:
LOG.warning("Unsuccessful attempt to edit fullname for %s: %s" % (username, e))
return error(str(e))

Binary file not shown.

View File

@ -27,7 +27,11 @@ class Tools():
#form validation
def input_validation(self, e):
def input_validation(self, e, ws=None):
if ws:
#accepts whitespaces
regex = r'^\w+( \w+)*$'
else:
regex = r'^\w+$'
return(bool(re.fullmatch(regex, e)))