# Account with uid does not exist, yet
return False
+ def mail_is_valid(self, mail):
+ username, delim, domain = mail.partition("@")
+
+ # There must be an @ and a domain part
+ if not domain:
+ return False
+
+ # The domain cannot end on a dot
+ if domain.endswith("."):
+ return False
+
+ # The domain should at least have one dot to fully qualified
+ if not "." in domain:
+ return False
+
+ # Looks like a valid email address
+ return True
+
def mail_is_blacklisted(self, mail):
username, delim, domain = mail.partition("@")
if self.uid_exists(uid):
raise ValueError("UID exists: %s" % uid)
+ # Check if the email address is valid
+ if not self.mail_is_valid(email):
+ raise ValueError("Email is invalid: %s" % email)
+
# Check if the email address is blacklisted
if self.mail_is_blacklisted(email):
raise ValueError("Email is blacklisted: %s" % email)
pattern="[a-z_][a-z0-9_-]{3,31}">
</div>
<div id="uid-invalid" class="invalid-feedback">
- {{ _("Please choose a username in UNIX format with at least four characters, starting with a lowercase letter, followed by only lowercase letters, digits, dash and underscore.") }}
+ {{ _("Please choose a username in UNIX format with at least four characters, starting with a lowercase letter, followed by only lowercase letters, digits, dash and underscore") }}
</div>
<div id="uid-taken" class="invalid-feedback">
- {{ _("This username is not available.") }}
+ {{ _("This username is not available") }}
</div>
</div>
<input type="email" class="form-control"
name="email" placeholder="{{ _("Email Address") }}" required>
<div id="email-invalid" class="invalid-feedback">
- {{ _("This email address cannot be used.") }}
+ {{ _("This email address is invalid") }}
+ </div>
+ <div id="email-blacklisted" class="invalid-feedback">
+ {{ _("This email address cannot be used") }}
</div>
<div id="email-taken" class="invalid-feedback">
- {{ _("This email address is already in use.") }}
+ {{ _("This email address is already in use") }}
</div>
</div>
$("#email-invalid").show();
break;
+ case "blacklisted":
+ email.addClass("is-invalid");
+ $("#email-blacklisted").show();
+ break;
+
case "taken":
email.addClass("is-invalid");
$("#email-taken").show();
if not email:
result = "empty"
+ elif not self.backend.accounts.mail_is_valid(email):
+ result = "invalid"
+
# Check if this email address is blacklisted
elif self.backend.accounts.mail_is_blacklisted(email):
- result = "invalid"
+ result = "blacklisted"
# Check if this email address is already useed
elif self.backend.accounts.get_by_mail(email):