From b4ad8d2a5afdf40901d2b3620e6ca2c10f066357 Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Mon, 4 Nov 2013 17:08:39 -0500 Subject: [PATCH] Factor out Google Apps user-not-registered logic (imported from commit ba1d9da60df01f063cbfc0374130b655b7555b4a) --- zerver/views/__init__.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 668ddb1616..8e3689c672 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -454,6 +454,24 @@ def create_homepage_form(request, user_info=None): # providing it. return HomepageForm(domain=request.session.get("domain")) +def maybe_send_to_registration(request, email, full_name=''): + form = create_homepage_form(request, user_info={'email': email}) + request.verified_email = None + if form.is_valid(): + # Construct a PreregistrationUser object and send the user over to + # the confirmation view. + prereg_user = create_preregistration_user(email, request) + return redirect("".join(( + "/", + # Split this so we only get the part after the / + Confirmation.objects.get_link_for_object(prereg_user).split("/", 3)[3], + '?gafyd_name=', + # urllib does not handle Unicode, so coerece to encoded byte string + # Explanation: http://stackoverflow.com/a/5605354/90777 + urllib.quote_plus(full_name.encode('utf8'))))) + else: + return render_to_response('zerver/accounts_home.html', {'form': form}) + def handle_openid_errors(request, issue, openid_response=None): if issue == "Unknown user": if openid_response is not None and openid_response.status == openid_SUCCESS: @@ -462,22 +480,7 @@ def handle_openid_errors(request, issue, openid_response=None): full_name = " ".join(( ax_response.get('http://axschema.org/namePerson/first')[0], ax_response.get('http://axschema.org/namePerson/last')[0])) - form = create_homepage_form(request, user_info={'email': google_email}) - request.verified_email = None - if form.is_valid(): - # Construct a PreregistrationUser object and send the user over to - # the confirmation view. - prereg_user = create_preregistration_user(google_email, request) - return redirect("".join(( - "/", - # Split this so we only get the part after the / - Confirmation.objects.get_link_for_object(prereg_user).split("/", 3)[3], - '?gafyd_name=', - # urllib does not handle Unicode, so coerece to encoded byte string - # Explanation: http://stackoverflow.com/a/5605354/90777 - urllib.quote_plus(full_name.encode('utf8'))))) - else: - return render_to_response('zerver/accounts_home.html', {'form': form}) + return maybe_send_to_registration(request, google_email, full_name=full_name) return default_render_failure(request, issue) def process_openid_login(request):