Factor out Google Apps user-not-registered logic

(imported from commit ba1d9da60df01f063cbfc0374130b655b7555b4a)
This commit is contained in:
Luke Faraone 2013-11-04 17:08:39 -05:00
parent a34731ed00
commit b4ad8d2a5a
1 changed files with 19 additions and 16 deletions

View File

@ -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):