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,20 +454,13 @@ def create_homepage_form(request, user_info=None):
# providing it.
return HomepageForm(domain=request.session.get("domain"))
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:
ax_response = ax.FetchResponse.fromSuccessResponse(openid_response)
google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
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})
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(google_email, request)
prereg_user = create_preregistration_user(email, request)
return redirect("".join((
"/",
# Split this so we only get the part after the /
@ -478,6 +471,16 @@ def handle_openid_errors(request, issue, openid_response=None):
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:
ax_response = ax.FetchResponse.fromSuccessResponse(openid_response)
google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
full_name = " ".join((
ax_response.get('http://axschema.org/namePerson/first')[0],
ax_response.get('http://axschema.org/namePerson/last')[0]))
return maybe_send_to_registration(request, google_email, full_name=full_name)
return default_render_failure(request, issue)
def process_openid_login(request):