Allow any user with a @mit.edu to register for Zulip.

We add a new validator that ensures that people who sign up with @mit.edu
addresses are in fact MIT users.

This closes #1612.

(imported from commit 1e30794b1615dd57cb0e367d1fa186a877253357)
This commit is contained in:
Luke Faraone 2013-08-11 15:47:28 -07:00
parent 368ace069c
commit cb2e993393
2 changed files with 18 additions and 4 deletions

View File

@ -9,6 +9,7 @@ from zproject import settings
from zerver.models import Realm, get_user_profile_by_email, UserProfile, \
completely_open
from zerver.lib.actions import do_change_password
import DNS
def is_inactive(value):
try:
@ -26,6 +27,19 @@ def isnt_mit(value):
if "@mit.edu" in value:
raise ValidationError(mark_safe(u'Zulip for MIT is by invitation only. ' + SIGNUP_STRING))
def not_mit_mailing_list(value):
# I don't want ec-discuss signed up for Zulip
if "@mit.edu" in value:
username = value.rsplit("@", 1)[0]
# Check whether the user exists and can get mail.
try:
DNS.dnslookup("%s.pobox.ns.athena.mit.edu" % username, DNS.Type.TXT)
except DNS.Base.ServerError, e:
if e.rcode == DNS.Status.NXDOMAIN:
raise ValidationError(mark_safe(u'That user does not exist at MIT or is a <a href="https://ist.mit.edu/email-lists">mailing list</a>. If you want to sign up an alias for Zulip, <a href="mailto:support@zulip.com">contact us</a>.'))
else:
raise
class RegistrationForm(forms.Form):
full_name = forms.CharField(max_length=100)
password = forms.CharField(widget=forms.PasswordInput, max_length=100)
@ -42,7 +56,7 @@ class HomepageForm(forms.Form):
if settings.ALLOW_REGISTER:
email = forms.EmailField()
else:
validators = [isnt_mit, is_inactive]
validators = [not_mit_mailing_list, is_inactive]
email = forms.EmailField(validators=validators)
def __init__(self, *args, **kwargs):

View File

@ -36,7 +36,7 @@ from zerver.lib.actions import do_remove_subscription, bulk_remove_subscriptions
user_email_is_unique, do_invite_users, do_refer_friend
from zerver.lib.create_user import random_api_key
from zerver.forms import RegistrationForm, HomepageForm, ToSForm, CreateBotForm, \
is_inactive, isnt_mit
is_inactive, isnt_mit, not_mit_mailing_list
from django.views.decorators.csrf import csrf_exempt, csrf_protect
from django_openid_auth.views import default_render_failure, login_complete
from openid.consumer.consumer import SUCCESS as openid_SUCCESS
@ -405,8 +405,8 @@ def json_invite_users(request, user_profile, invitee_emails=REQ):
if settings.ALLOW_REGISTER == False:
try:
isnt_mit(user_profile.email)
except ValidationError:
return json_error("Invitations are not enabled for MIT at this time.")
except ValidationError, e:
return json_error(e.message)
if not invitee_emails:
return json_error("You must specify at least one email address.")