From: dwickwire Date: Wed, 23 Nov 2011 22:01:48 +0000 (-0600) Subject: Saving the service protectively. Also using user from the request for socialauth... X-Git-Tag: 22.4~62 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/d20955a26f2dbfe2480c601c2e209be1a43060e1?hp=60a84fd652cffdf0754260067fa6fa5f16742014 Saving the service protectively. Also using user from the request for socialauth logins. --- diff --git a/cas_provider/urls.py b/cas_provider/urls.py index 8edc91a..e8b8a14 100644 --- a/cas_provider/urls.py +++ b/cas_provider/urls.py @@ -4,6 +4,7 @@ from views import * urlpatterns = patterns('', url(r'^login/', login), + url(r'^socialauth-login/$', socialauth_login), url(r'^validate/', validate), url(r'^logout/', logout), ) \ No newline at end of file diff --git a/cas_provider/views.py b/cas_provider/views.py index d76e60b..6a13b22 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -12,7 +12,8 @@ __all__ = ['login', 'validate', 'logout'] def login(request, template_name='cas/login.html', success_redirect='/account/'): service = request.GET.get('service', None) - request.session['service'] = service + if service is not None: + request.session['service'] = service if request.user.is_authenticated(): if service is not None: ticket = create_service_ticket(request.user, service) @@ -53,11 +54,17 @@ def login(request, template_name='cas/login.html', success_redirect='/account/') form = LoginForm(service) return render_to_response(template_name, {'form': form, 'errors': errors}, context_instance=RequestContext(request)) -def socialauth_login(request, user, template_name='cas/login.html', success_redirect='/account/'): +def socialauth_login(request, template_name='cas/login.html', success_redirect='/account/'): """ Similiar to login but user has been authenticated already through social auth. This step authenticates the login and generates a service ticket. """ - service = request.session['service'] + user = request.user + user.backend = 'django.contrib.auth.backends.ModelBackend' + if request.session.has_key('service'): + service = request.session['service'] + del request.session['service'] + else: + service = '/' errors = [] if user is not None: if user.is_active: