diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 25c6fd3..4d2cb3a 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,6 +1,10 @@ Changelog ========= +2.6 - (2021-04-08) +--------------------------- +* add email validation (replacing validate_email package) [dumitval] + 2.5 - (2021-01-08) --------------------------- * Bugfix related to encoding in search [dumitval] diff --git a/eea/usersdb/db_agent.py b/eea/usersdb/db_agent.py index 67c60ba..97c19de 100644 --- a/eea/usersdb/db_agent.py +++ b/eea/usersdb/db_agent.py @@ -994,7 +994,6 @@ def set_user_info(self, user_id, new_info): log.info("Modifying info for user %r", user_id) for dn, modify_statements in six.iteritems(diff): - # import pdb; pdb.set_trace() # no longer needed ? result = self.conn.modify_s(dn, tuple(modify_statements)) assert result[:2] == (ldap.RES_MODIFY, []) @@ -1439,6 +1438,15 @@ def members_in_org(self, org_id): return [self._user_id(d) for d in attr['uniqueMember'] if d.decode() != ''] + @log_ldap_exceptions + def org_country(self, org_id): + ''' return two letter ISD country code of organisation ''' + query_dn = self._org_dn(org_id) + result = self.conn.search_s(query_dn, ldap.SCOPE_BASE, + attrlist=('c',)) + assert len(result) == 1 + return result[0][1]['c'][0].decode('utf-8') + @log_ldap_exceptions def pending_members_in_org(self, org_id): ''' list pending members of org ''' diff --git a/eea/usersdb/schema.py b/eea/usersdb/schema.py index 5908a58..0dcabf2 100644 --- a/eea/usersdb/schema.py +++ b/eea/usersdb/schema.py @@ -1,4 +1,5 @@ ''' users db schema ''' +import re from six.moves import range import colander import phonenumbers @@ -10,7 +11,7 @@ "country / area code provided. If you second check and believe " "the number is correct, please contact HelpDesk.") ) -INVALID_EMAIL = "Invalid email format" +INVALID_EMAIL = "Invalid email format %s" NUMBER_FORMAT = phonenumbers.PhoneNumberFormat.INTERNATIONAL @@ -74,9 +75,14 @@ def _latin_validator(node, value): # max length for domain name labels is 63 characters per RFC 1034 _url_validator = colander.Regex(r'^http[s]?\://', msg=INVALID_URL) -_email_validator = colander.Regex( - r"(?:^|\s)[-a-z-A-Z0-9_.']+@(?:[-a-z-A-Z0-9]+\.)+[a-z-A-Z]{2,63}(?:\s|$)", - msg=INVALID_EMAIL) + + +def _email_validator(node, value): + """ email validator """ + pattern = (r"(?:^|\s)[-a-z-A-Z0-9_.']+@(?:[-a-z-A-Z0-9]+\.)+[a-z-A-Z]" + r"{2,63}(?:\s|$)") + if not re.match(pattern, value): + raise colander.Invalid(node, INVALID_EMAIL % value) class UserInfoSchema(colander.MappingSchema): diff --git a/eea/usersdb/version.txt b/eea/usersdb/version.txt index 95e3ba8..5154b3f 100644 --- a/eea/usersdb/version.txt +++ b/eea/usersdb/version.txt @@ -1 +1 @@ -2.5 +2.6