def signin(request, template_name='authopenid/signin.html', redirect_field_name=REDIRECT_FIELD_NAME, openid_form=OpenidSigninForm, auth_form=AuthenticationForm, on_failure=None, extra_context=None): if on_failure is None: on_failure = signin_failure redirect_to = request.REQUEST.get(redirect_field_name, '') form1 = openid_form() form2 = auth_form() if request.POST: if not redirect_to or '://' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL if 'openid_url' in request.POST.keys(): form1 = openid_form(data=request.POST) if form1.is_valid(): redirect_url = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_signin'), urllib.urlencode({redirect_field_name: redirect_to})) return ask_openid(request, form1.cleaned_data['openid_url'], redirect_url, on_failure=on_failure) else: # perform normal django authentification form2 = auth_form(data=request.POST) if form2.is_valid(): login(request, form2.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) return render_to_response(template_name, { 'form1': form1, 'form2': form2, redirect_field_name: redirect_to, 'msg': request.GET.get('msg', '') }, context_instance=_build_context( request, extra_context=extra_context))
def signin( request, template_name="authopenid/signin.html", redirect_field_name=REDIRECT_FIELD_NAME, openid_form=OpenidSigninForm, auth_form=AuthenticationForm, on_failure=None, extra_context=None, ): if on_failure is None: on_failure = signin_failure redirect_to = request.REQUEST.get(redirect_field_name, "") form1 = openid_form() form2 = auth_form() if request.POST: if not redirect_to or "://" in redirect_to or " " in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL if "openid_url" in request.POST.keys(): form1 = openid_form(data=request.POST) if form1.is_valid(): redirect_url = "%s%s?%s" % ( get_url_host(request), reverse("user_complete_signin"), urllib.urlencode({redirect_field_name: redirect_to}), ) return ask_openid(request, form1.cleaned_data["openid_url"], redirect_url, on_failure=on_failure) else: # perform normal django authentification form2 = auth_form(data=request.POST) if form2.is_valid(): login(request, form2.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) return render_to_response( template_name, {"form1": form1, "form2": form2, redirect_field_name: redirect_to, "msg": request.GET.get("msg", "")}, context_instance=_build_context(request, extra_context=extra_context), )
def associate(request, template_name='authopenid/associate.html', openid_form=AssociateOpenID, redirect_field_name='/', on_failure=associate_failure, extra_context=None): nb_associated_openids, associated_openids = get_associate_openid(request.user) redirect_to = request.REQUEST.get(redirect_field_name, '') if request.POST: if 'a_openids' in request.POST.keys(): a_openids = [] if request.POST.get('a_openids','') is not '': a_openids = request.POST.getlist('a_openids') if len(a_openids) == nb_associated_openids and not request.user.has_usable_password(): if len(a_openids) > 1: msg = ["You can't remove these openids, You should set a password first."] else: msg = ["You can't remove this openid, You should set a password first."] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids' : associated_openids, 'nb_associated_openids' : nb_associated_openids, 'msg':msg, }, context_instance=_build_context(request, extra_context=extra_context)) return render_to_response("authopenid/dissociate.html",{ 'a_openids' : a_openids }, context_instance = RequestContext(request) ) else: form = openid_form(request.user, data=request.POST) if form.is_valid(): if ' ' in form.cleaned_data['openid_url'] or form.cleaned_data['openid_url'] in OPENID_PROVIDER: msg = ['You must enter a valid OpenID url'] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids' : associated_openids, 'nb_associated_openids' : nb_associated_openids, 'msg':msg, }, context_instance=_build_context(request, extra_context=extra_context)) if not redirect_to or '://' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL redirect_url = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_myassociate'), urllib.urlencode({ redirect_field_name: redirect_to }) ) return ask_openid(request, form.cleaned_data['openid_url'], redirect_url, on_failure=on_failure) else: msg = ['You must enter a valid OpenID url'] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids' : associated_openids, 'nb_associated_openids' : nb_associated_openids, 'msg':msg, }, context_instance=_build_context(request, extra_context=extra_context)) else: form = openid_form(request.user) msg = messages.get_messages(request) return render_to_response('authopenid/associate.html', { 'form': form, redirect_field_name: redirect_to, 'associated_openids' : associated_openids, 'nb_associated_openids' : nb_associated_openids, 'msg':msg, }, context_instance=_build_context(request, extra_context=extra_context))
def associate( request, template_name="authopenid/associate.html", openid_form=AssociateOpenID, redirect_field_name="/", on_failure=associate_failure, extra_context=None, ): nb_associated_openids, associated_openids = get_associate_openid(request.user) redirect_to = request.REQUEST.get(redirect_field_name, "") if request.POST: if "a_openids" in request.POST.keys(): a_openids = [] if request.POST.get("a_openids", "") is not "": a_openids = request.POST.getlist("a_openids") if len(a_openids) == nb_associated_openids and not request.user.has_usable_password(): if len(a_openids) > 1: msg = ["You can't remove these openids, You should set a password first."] else: msg = ["You can't remove this openid, You should set a password first."] return render_to_response( "authopenid/associate.html", { redirect_field_name: redirect_to, "associated_openids": associated_openids, "nb_associated_openids": nb_associated_openids, "msg": msg, }, context_instance=_build_context(request, extra_context=extra_context), ) return render_to_response( "authopenid/dissociate.html", {"a_openids": a_openids}, context_instance=RequestContext(request) ) else: form = openid_form(request.user, data=request.POST) if form.is_valid(): if " " in form.cleaned_data["openid_url"] or form.cleaned_data["openid_url"] in OPENID_PROVIDER: msg = ["You must enter a valid OpenID url"] return render_to_response( "authopenid/associate.html", { redirect_field_name: redirect_to, "associated_openids": associated_openids, "nb_associated_openids": nb_associated_openids, "msg": msg, }, context_instance=_build_context(request, extra_context=extra_context), ) if not redirect_to or "://" in redirect_to or " " in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL redirect_url = "%s%s?%s" % ( get_url_host(request), reverse("user_complete_myassociate"), urllib.urlencode({redirect_field_name: redirect_to}), ) return ask_openid(request, form.cleaned_data["openid_url"], redirect_url, on_failure=on_failure) else: msg = ["You must enter a valid OpenID url"] return render_to_response( "authopenid/associate.html", { redirect_field_name: redirect_to, "associated_openids": associated_openids, "nb_associated_openids": nb_associated_openids, "msg": msg, }, context_instance=_build_context(request, extra_context=extra_context), ) else: form = openid_form(request.user) msg = messages.get_messages(request) return render_to_response( "authopenid/associate.html", { "form": form, redirect_field_name: redirect_to, "associated_openids": associated_openids, "nb_associated_openids": nb_associated_openids, "msg": msg, }, context_instance=_build_context(request, extra_context=extra_context), )
def associate(request, template_name='authopenid/associate.html', openid_form=AssociateOpenID, redirect_field_name='/', on_failure=associate_failure, extra_context=None): nb_associated_openids, associated_openids = get_associate_openid( request.user) redirect_to = request.REQUEST.get(redirect_field_name, '') if request.POST: if 'a_openids' in request.POST.keys(): a_openids = [] if request.POST.get('a_openids', '') is not '': a_openids = request.POST.getlist('a_openids') if len( a_openids ) == nb_associated_openids and not request.user.has_usable_password( ): if len(a_openids) > 1: msg = [ "You can't remove these openids, You should set a password first." ] else: msg = [ "You can't remove this openid, You should set a password first." ] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids': associated_openids, 'nb_associated_openids': nb_associated_openids, 'msg': msg, }, context_instance=_build_context( request, extra_context=extra_context)) return render_to_response( "authopenid/dissociate.html", {'a_openids': a_openids}, context_instance=RequestContext(request)) else: form = openid_form(request.user, data=request.POST) if form.is_valid(): if ' ' in form.cleaned_data['openid_url'] or form.cleaned_data[ 'openid_url'] in OPENID_PROVIDER: msg = ['You must enter a valid OpenID url'] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids': associated_openids, 'nb_associated_openids': nb_associated_openids, 'msg': msg, }, context_instance=_build_context( request, extra_context=extra_context)) if not redirect_to or '://' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL redirect_url = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_myassociate'), urllib.urlencode({redirect_field_name: redirect_to})) return ask_openid(request, form.cleaned_data['openid_url'], redirect_url, on_failure=on_failure) else: msg = ['You must enter a valid OpenID url'] return render_to_response('authopenid/associate.html', { redirect_field_name: redirect_to, 'associated_openids': associated_openids, 'nb_associated_openids': nb_associated_openids, 'msg': msg, }, context_instance=_build_context( request, extra_context=extra_context)) else: form = openid_form(request.user) msg = messages.get_messages(request) return render_to_response('authopenid/associate.html', { 'form': form, redirect_field_name: redirect_to, 'associated_openids': associated_openids, 'nb_associated_openids': nb_associated_openids, 'msg': msg, }, context_instance=_build_context( request, extra_context=extra_context))