mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
Implement MIT signups.
Here we introduce a new manage.py command, activate_mit, which takes a number of usernames and sends out emails to the users with instructions on how to activate their accounts. (imported from commit f14401b55f915698e83ff27b86434f53e64685f3)
This commit is contained in:
14
templates/confirmation/confirm_mituser.html
Normal file
14
templates/confirmation/confirm_mituser.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{% extends "zephyr/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form id="register" action="/accounts/register/" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" value="{{ key }}" name="key"/>
|
||||||
|
<input type="hidden" value="1" name="from_confirmation"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#register").submit();
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
37
templates/confirmation/mituser_confirmation_email_body.txt
Normal file
37
templates/confirmation/mituser_confirmation_email_body.txt
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
Hello,
|
||||||
|
|
||||||
|
Thanks for agreeing to help test out Humbug.
|
||||||
|
|
||||||
|
There are a few steps you need to take to ensure Humbug works with your
|
||||||
|
MIT Zephyr account.
|
||||||
|
|
||||||
|
1) Create a password and activate your account:
|
||||||
|
<{{ activate_url }}>
|
||||||
|
|
||||||
|
2) Get your API key from the "Settings" panel and put it in your
|
||||||
|
Athena home directory at ~/Private/.humbug-api-key.
|
||||||
|
|
||||||
|
3) Copy over your Zephyr subscriptions by running the command below:
|
||||||
|
/mit/tabbott/humbug/zephyr_mirror.py --sync-subscriptions
|
||||||
|
|
||||||
|
4) Run the Zephyr mirroring script on a server with long-lived tickets.
|
||||||
|
/mit/tabbott/humbug/zephyr_mirror.py
|
||||||
|
|
||||||
|
The script copies personals you receive on Zephyr to Humbug, and
|
||||||
|
copies messages you send from Humbug to Zephyr. You should keep this
|
||||||
|
script always running in a session with Kerberos tickets.
|
||||||
|
|
||||||
|
You may want to run this with owl-screen or kchen's
|
||||||
|
cont-renew-notify.
|
||||||
|
|
||||||
|
|
||||||
|
5) Visit the running app at:
|
||||||
|
<https://humbughq.com/>
|
||||||
|
|
||||||
|
Feel free to send us a message via the Feedback button from within the
|
||||||
|
app if you have any questions or encounter any problems.
|
||||||
|
|
||||||
|
|
||||||
|
Cheers,
|
||||||
|
|
||||||
|
Jeff, Waseem, Jessica, Tim, Keegan, Luke, and Zev
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Activate your Humbug account
|
||||||
@@ -10,6 +10,13 @@ def is_unique(value):
|
|||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def is_active(value):
|
||||||
|
try:
|
||||||
|
if User.objects.get(email=value).is_active:
|
||||||
|
raise ValidationError(u'%s is already active' % value)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
class UniqueEmailField(forms.EmailField):
|
class UniqueEmailField(forms.EmailField):
|
||||||
default_validators = [validators.validate_email, is_unique]
|
default_validators = [validators.validate_email, is_unique]
|
||||||
|
|
||||||
|
|||||||
26
zephyr/management/commands/activate_mit.py
Normal file
26
zephyr/management/commands/activate_mit.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from optparse import make_option
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from confirmation.models import Confirmation
|
||||||
|
from zephyr.models import User, MitUser
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
option_list = BaseCommand.option_list + (
|
||||||
|
make_option('--resend', '-r', dest='resend', action='store_true',
|
||||||
|
help='Send tokens even if tokens were previously sent for the user.'),)
|
||||||
|
help = "Generate an activation email to send to MIT users."
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
for username in args:
|
||||||
|
email = username + "@mit.edu"
|
||||||
|
try:
|
||||||
|
User.objects.get(email=email)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
print username + ": User does not exist in database"
|
||||||
|
continue
|
||||||
|
mit_user, created = MitUser.objects.get_or_create(email=email)
|
||||||
|
if not created and not options["resend"]:
|
||||||
|
print username + ": User already exists. Use -r to resend."
|
||||||
|
else:
|
||||||
|
Confirmation.objects.send_confirmation(mit_user, email)
|
||||||
|
print username + ": Mailed."
|
||||||
|
|
||||||
@@ -161,7 +161,14 @@ class UserProfile(models.Model):
|
|||||||
|
|
||||||
class PreregistrationUser(models.Model):
|
class PreregistrationUser(models.Model):
|
||||||
email = models.EmailField(unique=True)
|
email = models.EmailField(unique=True)
|
||||||
# 0 is inactive, 1 is active
|
# status: whether an object has been confirmed.
|
||||||
|
# if confirmed, set to confirmation.settings.STATUS_ACTIVE
|
||||||
|
status = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
class MitUser(models.Model):
|
||||||
|
email = models.EmailField(unique=True)
|
||||||
|
# status: whether an object has been confirmed.
|
||||||
|
# if confirmed, set to confirmation.settings.STATUS_ACTIVE
|
||||||
status = models.IntegerField(default=0)
|
status = models.IntegerField(default=0)
|
||||||
|
|
||||||
# create_user_hack is the same as Django's User.objects.create_user,
|
# create_user_hack is the same as Django's User.objects.create_user,
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ from django.contrib.auth.views import login as django_login_page
|
|||||||
from zephyr.models import Message, UserProfile, Stream, Subscription, \
|
from zephyr.models import Message, UserProfile, Stream, Subscription, \
|
||||||
Recipient, get_display_recipient, get_huddle, Realm, UserMessage, \
|
Recipient, get_display_recipient, get_huddle, Realm, UserMessage, \
|
||||||
do_add_subscription, do_remove_subscription, do_change_password, \
|
do_add_subscription, do_remove_subscription, do_change_password, \
|
||||||
do_change_full_name, \
|
do_change_full_name, do_activate_user, \
|
||||||
create_user, do_send_message, create_user_if_needed, \
|
create_user, do_send_message, create_user_if_needed, \
|
||||||
create_stream_if_needed, PreregistrationUser, get_client
|
create_stream_if_needed, PreregistrationUser, get_client, MitUser, \
|
||||||
from zephyr.forms import RegistrationForm, HomepageForm, is_unique
|
User
|
||||||
|
from zephyr.forms import RegistrationForm, HomepageForm, is_unique, \
|
||||||
|
is_active
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from zephyr.decorator import asynchronous
|
from zephyr.decorator import asynchronous
|
||||||
@@ -98,10 +100,18 @@ def get_stream(stream_name, realm):
|
|||||||
@require_post
|
@require_post
|
||||||
def accounts_register(request):
|
def accounts_register(request):
|
||||||
key = request.POST['key']
|
key = request.POST['key']
|
||||||
email = Confirmation.objects.get(confirmation_key=key).content_object.email
|
confirmation = Confirmation.objects.get(confirmation_key=key)
|
||||||
|
email = confirmation.content_object.email
|
||||||
|
mit_beta_user = isinstance(confirmation.content_object, MitUser)
|
||||||
|
|
||||||
company_name = email.split('@')[-1]
|
company_name = email.split('@')[-1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if mit_beta_user:
|
||||||
|
# MIT users already exist, but are supposed to be inactive.
|
||||||
|
is_active(email)
|
||||||
|
else:
|
||||||
|
# Other users should not already exist at all.
|
||||||
is_unique(email)
|
is_unique(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' + urllib.quote_plus(email))
|
return HttpResponseRedirect(reverse('django.contrib.auth.views.login') + '?email=' + urllib.quote_plus(email))
|
||||||
@@ -117,8 +127,15 @@ def accounts_register(request):
|
|||||||
domain = email.split('@')[-1]
|
domain = email.split('@')[-1]
|
||||||
(realm, _) = Realm.objects.get_or_create(domain=domain)
|
(realm, _) = Realm.objects.get_or_create(domain=domain)
|
||||||
|
|
||||||
|
if mit_beta_user:
|
||||||
|
user = User.objects.get(email=email)
|
||||||
|
do_activate_user(user)
|
||||||
|
do_change_password(user, password)
|
||||||
|
do_change_full_name(user.userprofile, full_name)
|
||||||
|
else:
|
||||||
# FIXME: sanitize email addresses
|
# FIXME: sanitize email addresses
|
||||||
create_user(email, password, realm, full_name, short_name)
|
create_user(email, password, realm, full_name, short_name)
|
||||||
|
|
||||||
login(request, authenticate(username=email, password=password))
|
login(request, authenticate(username=email, password=password))
|
||||||
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user