Move accounts_register user creation code into its own function.

(imported from commit 353086cecef93b76d5271b69f52046bb5b5781cb)
This commit is contained in:
Tim Abbott
2013-12-09 17:30:28 -05:00
parent 51dcf85fa0
commit 995141954f

View File

@@ -322,9 +322,44 @@ def accounts_register(request):
else: else:
user_profile = do_create_user(email, password, realm, full_name, short_name) user_profile = do_create_user(email, password, realm, full_name, short_name)
# We want to add the default subs list iff there were no subs process_new_human_user(user_profile, prereg_user=prereg_user,
# specified when the user was invited. newsletter_data={"IP": request.META['REMOTE_ADDR']})
# This logs you in using the ZulipDummyBackend, since honestly nothing
# more fancy than this is required.
login(request, authenticate(username=user_profile.email, use_dummy_backend=True))
if first_in_realm:
assign_perm("administer", user_profile, user_profile.realm)
return HttpResponseRedirect(reverse('zerver.views.initial_invite_page'))
else:
return HttpResponseRedirect(reverse('zerver.views.home'))
return render_to_response('zerver/register.html',
{'form': form,
'company_name': domain,
'email': email,
'key': key,
'full_name': request.session.get('authenticated_full_name', None),
'lock_name': name_validated and settings.NAME_CHANGES_DISABLED
},
context_instance=RequestContext(request))
# Does the processing for a new user account:
# * Subscribes to default/invitation streams
# * Fills in some recent historical messages
# * Notifies other users in realm and Zulip about the signup
# * Deactivates PreregistrationUser objects
# * subscribe the user to newsletter if newsletter_data is specified
def process_new_human_user(user_profile, prereg_user=None, newsletter_data=None):
mit_beta_user = user_profile.realm.domain == "mit.edu"
if prereg_user is not None:
streams = prereg_user.streams.all() streams = prereg_user.streams.all()
else:
streams = []
# If the user's invitation didn't explicitly list some streams, we
# add the default streams
if len(streams) == 0: if len(streams) == 0:
streams = get_default_subs(user_profile) streams = get_default_subs(user_profile)
bulk_add_subscriptions(streams, [user_profile]) bulk_add_subscriptions(streams, [user_profile])
@@ -344,7 +379,8 @@ def accounts_register(request):
UserMessage.objects.bulk_create(ums_to_create) UserMessage.objects.bulk_create(ums_to_create)
# mit_beta_users don't have a referred_by field # mit_beta_users don't have a referred_by field
if not mit_beta_user and prereg_user.referred_by is not None and settings.NOTIFICATION_BOT is not None: if not mit_beta_user and prereg_user is not None and prereg_user.referred_by is not None \
and settings.NOTIFICATION_BOT is not None:
# This is a cross-realm private message. # This is a cross-realm private message.
internal_send_message(settings.NOTIFICATION_BOT, internal_send_message(settings.NOTIFICATION_BOT,
"private", prereg_user.referred_by.email, user_profile.realm.domain, "private", prereg_user.referred_by.email, user_profile.realm.domain,
@@ -353,47 +389,33 @@ def accounts_register(request):
user_profile.email, user_profile.email,
) )
) )
# Mark any other PreregistrationUsers that are STATUS_ACTIVE as inactive # Mark any other PreregistrationUsers that are STATUS_ACTIVE as
# so we can find the PreregistrationUser that we are actually working # inactive so we can keep track of the PreregistrationUser we
# with here # actually used for analytics
PreregistrationUser.objects.filter(email=email) \ if prereg_user is not None:
.exclude(id=prereg_user.id) \ PreregistrationUser.objects.filter(email__iexact=user_profile.email).exclude(
.update(status=0) id=prereg_user.id).update(status=0)
else:
PreregistrationUser.objects.filter(email__iexact=user_profile.email).update(status=0)
notify_new_user(user_profile) notify_new_user(user_profile)
if newsletter_data is not None:
# If the user was created automatically via the API, we may
# not want to register them for the newsletter
queue_json_publish( queue_json_publish(
"signups", "signups",
{ {
'EMAIL': email, 'EMAIL': user_profile.email,
'merge_vars': { 'merge_vars': {
'NAME': full_name, 'NAME': user_profile.full_name,
'REALM': domain, 'REALM': user_profile.realm.domain,
'OPTIN_IP': request.META['REMOTE_ADDR'], 'OPTIN_IP': newsletter_data["IP"],
'OPTIN_TIME': datetime.datetime.isoformat(datetime.datetime.now()), 'OPTIN_TIME': datetime.datetime.isoformat(datetime.datetime.now()),
}, },
}, },
lambda event: None) lambda event: None)
# This logs you in using the ZulipDummyBackend, since honestly nothing
# more fancy than this is required.
login(request, authenticate(username=email, use_dummy_backend=True))
if first_in_realm:
assign_perm("administer", user_profile, user_profile.realm)
return HttpResponseRedirect(reverse('zerver.views.initial_invite_page'))
else:
return HttpResponseRedirect(reverse('zerver.views.home'))
return render_to_response('zerver/register.html',
{'form': form,
'company_name': domain,
'email': email,
'key': key,
'full_name': request.session.get('authenticated_full_name', None),
'lock_name': name_validated and settings.NAME_CHANGES_DISABLED
},
context_instance=RequestContext(request))
@login_required(login_url = settings.HOME_NOT_LOGGED_IN) @login_required(login_url = settings.HOME_NOT_LOGGED_IN)
def accounts_accept_terms(request): def accounts_accept_terms(request):
email = request.user.email email = request.user.email