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:
Tim Abbott 2015-12-28 12:37:24 -08:00
parent 515249ce0a
commit c661bc17fb
2 changed files with 16 additions and 15 deletions

View File

@ -7,7 +7,7 @@ from django.contrib.auth.forms import SetPasswordForm, AuthenticationForm
from django.conf import settings
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 zproject.backends import password_auth_enabled
import DNS
@ -69,7 +69,9 @@ class HomepageForm(forms.Form):
def clean_email(self):
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
raise ValidationError(mark_safe(SIGNUP_STRING))

View File

@ -85,11 +85,16 @@ def accounts_register(request):
existing_user_profile = None
validators.validate_email(email)
# If someone invited you, you are joining their realm regardless
# of your e-mail address.
#
# MitUsers can't be referred and don't have a referred_by field.
if not mit_beta_user and prereg_user.referred_by:
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
# of your e-mail address.
#
# MitUsers can't be referred and don't have a referred_by field.
realm = prereg_user.referred_by.realm
domain = realm.domain
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
# realm.
domain = prereg_user.realm.domain
realm = get_realm(domain)
else:
domain = resolve_email_to_domain(email)
realm = get_realm(domain)
realm = get_realm(domain)
if realm and realm.deactivated:
# The user is trying to register for a deactivated realm. Advise them to
# contact support.
@ -635,13 +641,6 @@ def send_registration_completion_email(email, request):
additional_context=context)
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':
form = create_homepage_form(request, user_info=request.POST)
if form.is_valid():