From: Michael Tremer Date: Tue, 24 Dec 2019 11:16:58 +0000 (+0100) Subject: accounts: Check emails against our local blacklist X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66181c96b6f5c0bacc7b0adc849e6699c784d736;p=ipfire.org.git accounts: Check emails against our local blacklist This list holds throwaway domains and others that cannot be used to register an account. Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 42d16249..9b012234 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -305,6 +305,21 @@ class Accounts(Object): # Account with uid does not exist, yet return False + def mail_is_blacklisted(self, mail): + username, delim, domain = mail.partition("@") + + if domain: + return self.domain_is_blacklisted(domain) + + def domain_is_blacklisted(self, domain): + res = self.db.get("SELECT TRUE AS found FROM blacklisted_domains \ + WHERE domain = %s", domain) + + if res and res.found: + return True + + return False + def get_by_uid(self, uid): return self._search_one("(&(objectClass=person)(uid=%s))" % uid) @@ -370,6 +385,10 @@ class Accounts(Object): if self.uid_exists(uid): raise ValueError("UID exists: %s" % uid) + # Check if the email address is blacklisted + if self.mail_is_blacklisted(email): + raise ValueError("Email is blacklisted: %s" % email) + # Generate a random activation code activation_code = util.random_string(36) diff --git a/src/templates/auth/register.html b/src/templates/auth/register.html index c72607a1..313184fd 100644 --- a/src/templates/auth/register.html +++ b/src/templates/auth/register.html @@ -52,6 +52,12 @@
+
+ {{ _("This email address cannot be used.") }} +
+
+ {{ _("This email address is already in use.") }} +