# 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)
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)
<div class="form-group">
<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.") }}
+ </div>
+ <div id="email-taken" class="invalid-feedback">
+ {{ _("This email address is already in use.") }}
+ </div>
</div>
<button type="submit" class="btn btn-primary btn-block">
{% block javascript %}
<script>
var check_uid;
+ var check_email;
$("input[name=uid]").on("keyup", function(e) {
if (check_uid)
uid.removeClass("is-valid is-invalid");
// Hide all feedback
- $(".invalid-feedback").hide();
+ uid.siblings(".invalid-feedback").hide();
switch (data.result) {
case "ok":
);
}, 250);
});
+
+ $("input[name=email]").on("keyup", function(e) {
+ if (check_email)
+ clearTimeout(check_email);
+
+ var email = $(this);
+
+ check_email = setTimeout(function() {
+ $.get("/api/check/email", { email : email.val() },
+ function(data) {
+ // Reset all classes
+ email.removeClass("is-valid is-invalid");
+
+ // Hide all feedback
+ email.siblings(".invalid-feedback").hide();
+
+ switch (data.result) {
+ case "ok":
+ email.addClass("is-valid");
+ break;
+
+ case "invalid":
+ email.addClass("is-invalid");
+ $("#email-invalid").show();
+ break;
+
+ case "taken":
+ email.addClass("is-invalid");
+ $("#email-taken").show();
+ break;
+ }
+ }
+ );
+ }, 250);
+ });
</script>
{% end block %}
(r"/stats", people.StatsHandler),
# API
+ (r"/api/check/email", auth.APICheckEmail),
(r"/api/check/uid", auth.APICheckUID),
] + authentication_handlers)
class APICheckUID(base.APIHandler):
- @base.ratelimit(minutes=5, requests=100)
+ @base.ratelimit(minutes=1, requests=100)
def get(self):
uid = self.get_argument("uid")
result = None
# Username seems to be okay
self.finish({ "result" : result or "ok" })
+
+
+class APICheckEmail(base.APIHandler):
+ @base.ratelimit(minutes=1, requests=100)
+ def get(self):
+ email = self.get_argument("email")
+ result = None
+
+ if not email:
+ result = "empty"
+
+ # Check if this email address is blacklisted
+ elif self.backend.accounts.mail_is_blacklisted(email):
+ result = "invalid"
+
+ # Check if this email address is already useed
+ elif self.backend.accounts.get_by_mail(email):
+ result = "taken"
+
+ self.finish({ "result" : result or "ok" })