Ejemplo n.º 1
0
def success_openid_login(request, openid_response, redirect_field_name=REDIRECT_FIELD_NAME):
    """
    A view-helper to handle a successful OpenID authentication response.  Note that this
    doesn't mean we've found a matching user yet.  That's what this method
    does.  This view-helper requires adding ``openid_auth.models.OpenIDBackend`` to the
    ``settings.AUTHENTICATION_BACKENDS`` list.
    """
    #Get the OpenID URL
    openid_url = openid_response.identity_url
    #Call the built in django auth function
    #(NOTE: this call won't work without adding 'openid_auth.models.OpenIDBackend' to the settings.AUTHENTICATION_BACKENDS list)
    user = authenticate(openid_url=openid_url)
    if user:
        #Log in the user with the built-in django function
        auth_login(request, user)
        #Do we not yet have any openids in the session?
        if OPENIDS_SESSION_NAME not in request.session.keys():
            request.session[OPENIDS_SESSION_NAME] = []
        #Eliminate any duplicate openids in the session
        request.session[OPENIDS_SESSION_NAME] = [o for o in request.session[OPENIDS_SESSION_NAME] if o.openid != openid_url]
        #Add this new openid to the list
        request.session[OPENIDS_SESSION_NAME].append(from_openid_response(openid_response))
        #Get the page to redirect to
        redirect = request.REQUEST.get(redirect_field_name, None)
        if not redirect or not is_valid_redirect_url(redirect):
            redirect = settings.LOGIN_REDIRECT_URL
        return HttpResponseRedirect(redirect)
    else:
        #TODO: This should start the registration process
        return failure_openid_login(request,
                                    openid_response,
                                    _("The OpenID doesn't match any registered user."),
                                    redirect_field_name=REDIRECT_FIELD_NAME)
Ejemplo n.º 2
0
def default_on_success(request, identity_url, openid_response):
    if 'openids' not in request.session.keys():
        request.session['openids'] = []
    
    # Eliminate any duplicates
    request.session['openids'] = [
        o for o in request.session['openids'] if o.openid != identity_url
    ]
    request.session['openids'].append(from_openid_response(openid_response))
    
    # Set up request.openids and request.openid, reusing middleware logic
    OpenIDMiddleware().process_request(request)
    
    next = request.GET.get('next', '').strip()
    if not next or not is_valid_next_url(next):
        next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
    
    return HttpResponseRedirect(next)
Ejemplo n.º 3
0
def openid_login_on_success(request, identity_url, openid_response):
	if 'openids' not in request.session.keys():
		request.session['openids'] = []

	# Eliminate any duplicates
	request.session['openids'] = [
		o for o in request.session['openids'] if o.openid != identity_url
	]
	request.session['openids'].append(from_openid_response(openid_response))

	# TODO
	assoc = OpenIdAssociation.objects.filter(url=identity_url)
	if assoc.count() == 0:
		return HttpResponseRedirect('/openid/register/')
	else:
		auth_user = authenticate(openid_url=identity_url)
		login(request, auth_user)

	next = request.GET.get('next', '').strip()
	if not next or not is_valid_next_url(next):
		next = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')

	return HttpResponseRedirect(next)