[snowy] Use a session variable for redirection after login
- From: Sanford Armstrong <sharm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [snowy] Use a session variable for redirection after login
- Date: Mon, 20 Dec 2010 11:41:02 +0000 (UTC)
commit 8fd1c232384f772164254ab1591354259e930128
Author: Leon Handreke <leon handreke gmail com>
Date: Mon Nov 15 11:57:31 2010 +0100
Use a session variable for redirection after login
Doing this fixes OAuth for some more unusual authentication flows,
such as creating a new account or using username/password to log in.
This fixes bug #633067 and #629853.
accounts/middleware.py | 13 +++++++++++++
accounts/views.py | 7 ++++++-
settings.py | 1 +
3 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/accounts/middleware.py b/accounts/middleware.py
index e4bf2db..567966e 100644
--- a/accounts/middleware.py
+++ b/accounts/middleware.py
@@ -17,6 +17,9 @@
from django.middleware.common import CommonMiddleware
from django.utils import translation
+from django.http import HttpResponseRedirect
+
+from django.conf import settings
class LocaleMiddleware:
def process_view(self, request, view_func, view_args, view_kwargs):
@@ -25,3 +28,13 @@ class LocaleMiddleware:
if profile.language:
translation.activate(profile.language)
return None
+
+class LoginRedirectMiddleware:
+ def process_request(self, request):
+ if request.path == settings.LOGIN_REDIRECT_URL and \
+ request.session.get('login_complete_redirect', None) and \
+ request.user.is_authenticated():
+ redirect_to = request.session['login_complete_redirect']
+ # do not redirect the next time the user visits LOGIN_REDIRECT_URL
+ request.session['login_complete_redirect'] = None
+ return HttpResponseRedirect(redirect_to)
diff --git a/accounts/views.py b/accounts/views.py
index a9d48ac..36f7181 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -19,10 +19,11 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserChangeForm, PasswordChangeForm
from django.contrib.auth.models import User
-from django.contrib.auth import authenticate, login
+from django.contrib.auth import authenticate, login, REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.contrib import messages
+from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponseNotAllowed
@@ -85,6 +86,10 @@ def openid_registration(request, template_name='registration/registration_form.h
def openid_begin(request, **kwargs):
"""A wrapper view around the login_begin view in
django_openid_auth that features a nicer error display"""
+ redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
+ if redirect_to != '':
+ request.session['login_complete_redirect'] = redirect_to
+
return django_openid_auth.views.login_begin(request, render_failure=render_openid_failure,
**kwargs)
diff --git a/settings.py b/settings.py
index fec54e8..e21dc06 100644
--- a/settings.py
+++ b/settings.py
@@ -97,6 +97,7 @@ MIDDLEWARE_CLASSES = [
'django.middleware.locale.LocaleMiddleware',
'snowy.accounts.middleware.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'snowy.accounts.middleware.LoginRedirectMiddleware',
'django.middleware.transaction.TransactionMiddleware',
#'reversion.middleware.RevisionMiddleware',
'recaptcha_django.middleware.ReCaptchaMiddleware',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]