def _unique_email_validator(form, field): """ Check if the new email is unique. Skip this step if the email is the same as the current one. """ if field.data.lower() == current_user.email.lower(): return unique_email_validator(form, field)
def da_unique_email_validator(form, field): if daconfig['ldap login'].get( 'enable', False) and daconfig['ldap login'].get( 'base dn', None) is not None and daconfig['ldap login'].get( 'bind email', None) is not None and daconfig['ldap login'].get( 'bind password', None) is not None: ldap_server = daconfig['ldap login'].get('server', 'localhost').strip() base_dn = daconfig['ldap login']['base dn'].strip() search_filter = daconfig['ldap login'].get( 'search pattern', "mail=%s") % (form.email.data, ) connect = ldap.initialize('ldap://' + ldap_server) try: connect.simple_bind_s(daconfig['ldap login']['bind email'], daconfig['ldap login']['bind password']) if len(connect.search_s(base_dn, ldap.SCOPE_SUBTREE, search_filter)) > 0: raise ValidationError( word( "This Email is already in use. Please try another one." )) except ldap.LDAPError: pass if daconfig.get('confirm registration', False): return True return unique_email_validator(form, field)
def da_unique_email_validator(form, field): if daconfig['ldap login'].get('enable', False) and daconfig['ldap login'].get('base dn', None) is not None and daconfig['ldap login'].get('bind email', None) is not None and daconfig['ldap login'].get('bind password', None) is not None: ldap_server = daconfig['ldap login'].get('server', 'localhost').strip() base_dn = daconfig['ldap login']['base dn'].strip() search_filter = daconfig['ldap login'].get('search pattern', "mail=%s") % (form.email.data,) connect = ldap.open(ldap_server) try: connect.simple_bind_s(daconfig['ldap login']['bind email'], daconfig['ldap login']['bind password']) if len(connect.search_s(base_dn, ldap.SCOPE_SUBTREE, search_filter)) > 0: raise ValidationError(word("This Email is already in use. Please try another one.")) except ldap.LDAPError: pass return unique_email_validator(form, field)