mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Clean up and document clean_email code path.
This commit is contained in:
@@ -41,16 +41,18 @@ def get_registration_string(domain):
|
|||||||
'Please register your account <a href=%(url)s>here</a>.') % {'url': register_url}
|
'Please register your account <a href=%(url)s>here</a>.') % {'url': register_url}
|
||||||
return register_account_string
|
return register_account_string
|
||||||
|
|
||||||
def has_valid_realm(value):
|
def get_valid_realm(value):
|
||||||
# type: (str) -> bool
|
# type: (str) -> Optional[Realm]
|
||||||
# Checks if there is a realm without invite_required
|
"""Checks if there is a realm without invite_required
|
||||||
# matching the domain of the input e-mail.
|
matching the domain of the input e-mail."""
|
||||||
realm = get_realm(resolve_email_to_domain(value))
|
realm = get_realm(resolve_email_to_domain(value))
|
||||||
return realm is not None and not realm.invite_required
|
if realm is None or realm.invite_required:
|
||||||
|
return None
|
||||||
|
return realm
|
||||||
|
|
||||||
def not_mit_mailing_list(value):
|
def not_mit_mailing_list(value):
|
||||||
# type: (str) -> bool
|
# type: (str) -> bool
|
||||||
# I don't want ec-discuss signed up for Zulip
|
"""Prevent MIT mailing lists from signing up for Zulip"""
|
||||||
if "@mit.edu" in value:
|
if "@mit.edu" in value:
|
||||||
username = value.rsplit("@", 1)[0]
|
username = value.rsplit("@", 1)[0]
|
||||||
# Check whether the user exists and can get mail.
|
# Check whether the user exists and can get mail.
|
||||||
@@ -94,11 +96,33 @@ class HomepageForm(forms.Form):
|
|||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
|
"""Returns the email if and only if the user's email address is
|
||||||
|
allowed to join the realm they are trying to join."""
|
||||||
data = self.cleaned_data['email']
|
data = self.cleaned_data['email']
|
||||||
if (get_unique_open_realm() or
|
# If the server has a unique open realm, pass
|
||||||
completely_open(self.domain) or
|
if get_unique_open_realm():
|
||||||
(has_valid_realm(data) and not_mit_mailing_list(data))):
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
# If a realm is specified and that realm is open, pass
|
||||||
|
if completely_open(self.domain):
|
||||||
|
return data
|
||||||
|
|
||||||
|
# If no realm is specified, fail
|
||||||
|
realm = get_valid_realm(data)
|
||||||
|
if realm is None:
|
||||||
|
raise ValidationError(mark_safe(SIGNUP_STRING))
|
||||||
|
|
||||||
|
# If it's a clear realm not used for Zephyr mirroring, pass
|
||||||
|
if not realm.is_zephyr_mirror_realm:
|
||||||
|
return data
|
||||||
|
|
||||||
|
# At this point, the user is trying to join a Zephyr mirroring
|
||||||
|
# realm. We confirm that they are a real account (not a
|
||||||
|
# mailing list), and if so, let them in.
|
||||||
|
if not_mit_mailing_list(data):
|
||||||
|
return data
|
||||||
|
|
||||||
|
# Otherwise, the user is an MIT mailing list, and we return failure
|
||||||
raise ValidationError(mark_safe(SIGNUP_STRING))
|
raise ValidationError(mark_safe(SIGNUP_STRING))
|
||||||
|
|
||||||
class RealmCreationForm(forms.Form):
|
class RealmCreationForm(forms.Form):
|
||||||
|
|||||||
Reference in New Issue
Block a user