From d1ed37fa9ed080d0c05e7b8c2746dc357314dc60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Fri, 27 May 2011 12:16:27 -0300 Subject: [PATCH] Add last login backend name to session on login. Closes gh-76 --- example/app/views.py | 1 + example/templates/done.html | 1 + social_auth/views.py | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/example/app/views.py b/example/app/views.py index a17a0cf..ecc9825 100644 --- a/example/app/views.py +++ b/example/app/views.py @@ -22,6 +22,7 @@ def done(request): names = request.user.social_auth.values_list('provider', flat=True) ctx = dict((name.lower().replace('-', '_'), True) for name in names) ctx['version'] = version + ctx['last_login'] = request.session.get('social_auth_last_login_backend') return render_to_response('done.html', ctx, RequestContext(request)) def error(request): diff --git a/example/templates/done.html b/example/templates/done.html index 2b67f3d..f5abc9b 100644 --- a/example/templates/done.html +++ b/example/templates/done.html @@ -11,6 +11,7 @@ Email: {{ user.email|default:"Not provided" }} First name: {{ user.first_name|default:"Not provided" }} Last name: {{ user.last_name|default:"Not provided" }} + Last login backend: {{ last_login }} diff --git a/social_auth/views.py b/social_auth/views.py index 5e94375..026be13 100644 --- a/social_auth/views.py +++ b/social_auth/views.py @@ -13,6 +13,8 @@ from social_auth.utils import sanitize_redirect DEFAULT_REDIRECT = getattr(settings, 'SOCIAL_AUTH_LOGIN_REDIRECT_URL', '') or \ getattr(settings, 'LOGIN_REDIRECT_URL', '') +SOCIAL_AUTH_LAST_LOGIN = getattr(settings, 'SOCIAL_AUTH_LAST_LOGIN', + 'social_auth_last_login_backend') def auth(request, backend): @@ -56,6 +58,9 @@ def complete_process(request, backend): if social_user.expiration_delta(): request.session.set_expiry(social_user.expiration_delta()) url = request.session.pop(REDIRECT_FIELD_NAME, '') or DEFAULT_REDIRECT + + # store last login backend name in session + request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider else: url = getattr(settings, 'LOGIN_ERROR_URL', settings.LOGIN_URL) return HttpResponseRedirect(url) -- 2.39.5