mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Fix support for having a unique, open realm.
The previous implementation didn't work because HomepageForm rejected the email as not having a domain. Additionally, the logic in accounts_register didn't work with Google auth because that code path doesn't pass through accounts_home. Since whether there's a unique open realm for the server is effectively a configuration property, we can fix the bug and make the logic clearer by moving it into the "figure out the user's realm" function.
This commit is contained in:
@@ -7,7 +7,7 @@ from django.contrib.auth.forms import SetPasswordForm, AuthenticationForm
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
|
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
|
||||||
completely_open, resolve_email_to_domain, get_realm
|
completely_open, resolve_email_to_domain, get_realm, get_unique_open_realm
|
||||||
from zerver.lib.actions import do_change_password, is_inactive
|
from zerver.lib.actions import do_change_password, is_inactive
|
||||||
from zproject.backends import password_auth_enabled
|
from zproject.backends import password_auth_enabled
|
||||||
import DNS
|
import DNS
|
||||||
@@ -69,7 +69,9 @@ class HomepageForm(forms.Form):
|
|||||||
|
|
||||||
def clean_email(self):
|
def clean_email(self):
|
||||||
data = self.cleaned_data['email']
|
data = self.cleaned_data['email']
|
||||||
if completely_open(self.domain) or has_valid_realm(data) and not_mit_mailing_list(data):
|
if (get_unique_open_realm() or
|
||||||
|
completely_open(self.domain) or
|
||||||
|
(has_valid_realm(data) and not_mit_mailing_list(data))):
|
||||||
return data
|
return data
|
||||||
raise ValidationError(mark_safe(SIGNUP_STRING))
|
raise ValidationError(mark_safe(SIGNUP_STRING))
|
||||||
|
|
||||||
|
|||||||
@@ -85,11 +85,16 @@ def accounts_register(request):
|
|||||||
existing_user_profile = None
|
existing_user_profile = None
|
||||||
|
|
||||||
validators.validate_email(email)
|
validators.validate_email(email)
|
||||||
|
|
||||||
|
unique_open_realm = get_unique_open_realm()
|
||||||
|
if unique_open_realm:
|
||||||
|
realm = unique_open_realm
|
||||||
|
domain = realm.domain
|
||||||
|
elif not mit_beta_user and prereg_user.referred_by:
|
||||||
# If someone invited you, you are joining their realm regardless
|
# If someone invited you, you are joining their realm regardless
|
||||||
# of your e-mail address.
|
# of your e-mail address.
|
||||||
#
|
#
|
||||||
# MitUsers can't be referred and don't have a referred_by field.
|
# MitUsers can't be referred and don't have a referred_by field.
|
||||||
if not mit_beta_user and prereg_user.referred_by:
|
|
||||||
realm = prereg_user.referred_by.realm
|
realm = prereg_user.referred_by.realm
|
||||||
domain = realm.domain
|
domain = realm.domain
|
||||||
if realm.restricted_to_domain and domain != resolve_email_to_domain(email):
|
if realm.restricted_to_domain and domain != resolve_email_to_domain(email):
|
||||||
@@ -99,10 +104,11 @@ def accounts_register(request):
|
|||||||
# happens if you sign up through a special URL for an open
|
# happens if you sign up through a special URL for an open
|
||||||
# realm.
|
# realm.
|
||||||
domain = prereg_user.realm.domain
|
domain = prereg_user.realm.domain
|
||||||
|
realm = get_realm(domain)
|
||||||
else:
|
else:
|
||||||
domain = resolve_email_to_domain(email)
|
domain = resolve_email_to_domain(email)
|
||||||
|
|
||||||
realm = get_realm(domain)
|
realm = get_realm(domain)
|
||||||
|
|
||||||
if realm and realm.deactivated:
|
if realm and realm.deactivated:
|
||||||
# The user is trying to register for a deactivated realm. Advise them to
|
# The user is trying to register for a deactivated realm. Advise them to
|
||||||
# contact support.
|
# contact support.
|
||||||
@@ -635,13 +641,6 @@ def send_registration_completion_email(email, request):
|
|||||||
additional_context=context)
|
additional_context=context)
|
||||||
|
|
||||||
def accounts_home(request):
|
def accounts_home(request):
|
||||||
# First we populate request.session with a domain if
|
|
||||||
# there is a single realm, which is open.
|
|
||||||
# This is then used in HomepageForm and in creating a PreregistrationUser
|
|
||||||
unique_realm = get_unique_open_realm()
|
|
||||||
if unique_realm:
|
|
||||||
request.session['domain'] = unique_realm.domain
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = create_homepage_form(request, user_info=request.POST)
|
form = create_homepage_form(request, user_info=request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|||||||
Reference in New Issue
Block a user