Commits

offline committed 1c7ad0a

openid now also support 'next' GET argument

Comments (0)

Files changed (1)

openauth/views.py

     if request.method == "POST":
         form = LoginForm(request, request.POST)
         if form.is_valid():
-            return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, 
-                                        openauth.lang.SUCCESSFULL_LOGIN)
+            redirect_url = request.GET.get("next") or openauth.settings.LOGIN_REDIRECT_URL
+            return notify_user.success(request, redirect_url, openauth.lang.SUCCESSFULL_LOGIN)
     else:
         form = LoginForm(request=request)
     return {'form': form}
     if request.method == "POST":
         form = OpenIDLoginForm(request.POST, request=request)
         if form.is_valid():
+            next_url = request.GET.get("next") or openauth.settings.LOGIN_REDIRECT_URL
+            request.session['next_url'] = next_url
             return redirect(form.redirect_url)
     else:
         form = OpenIDLoginForm()
     elif resp.status == consumer.FAILURE:
         return notify_user.error(request, "/", _('OpenID authorization failed. Reason: %s') % resp.message)
     elif resp.status == consumer.SUCCESS:
+        redirect_url = request.session['next_url']
         if request.user.is_authenticated():
             try:
                 user = OpenID.objects.get(url=resp.identity_url).user
             except OpenID.DoesNotExist:
                 OpenID(user=request.user, url=resp.identity_url).save()
-            return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, _("Your OpenID account is saved"))
+            del request.session['next_url']
+            return notify_user.success(request, redirect_url, _("Your OpenID account is saved"))
         else:
             user = auth.authenticate(openid_url=resp.identity_url)
             if user:
                     return notify_user.success(request, "/", _("Your account is not activated. Please activate it first."))
                 else:
                     auth.login(request, user)
-                    return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, _("You have successfully authorized via OpenID"))
+                    del request.session['next_url']
+                    return notify_user.success(request, redirect_url, _("You have successfully authorized via OpenID"))
             else:
                 if not openauth.settings.REGISTRATION_ALLOWED:
                     return notify_user.notice(request, '/', openauth.lang.REGISTRATION_DISABLED)
                         user = auth.authenticate(openid_url=resp.identity_url)
                         if user:
                             auth.login(request, user)
-                            return notify_user.success(request, openauth.settings.LOGIN_REDIRECT_URL, _("You have successfully authorized via OpenID"))
+                            del request.session['next_url']
+                            return notify_user.success(request, redirect_url, _("You have successfully authorized via OpenID"))
                 else:
                     dump_openid_data(request, resp)
                     return redirect(reverse('openauth-openid-registration'))
             user = auth.authenticate(openid_url=openid_url)
             if user:
                 auth.login(request, user)
-                return notify_user.success(request, "/", _("You have been successfully registred"))
+                redirect_url = request.session['next_url']
+                del request.session['next_url']
+                return notify_user.success(request, redirect_url, _("You have been successfully registred"))
     else:                                        
         initial = {}
         if openauth.settings.OPENID_PROFILE_MAPPING: