X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/blobdiff_plain/d36533f533bc0420622298afb19c61991d48eba8..8ace0586471d741bbe1d55dca48f524a3d385852:/cas_provider/views.py?ds=sidebyside diff --git a/cas_provider/views.py b/cas_provider/views.py index 2e5e1f5..5ba62e6 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -21,12 +21,13 @@ __all__ = ['login', 'validate', 'logout'] def _build_service_url(service, ticket): if service.find('?') == -1: - return service + '?ticket=' + ticket.ticket + return service + '?ticket=' + ticket else: - return service + '&ticket=' + ticket.ticket + return service + '&ticket=' + ticket -def login(request, template_name='cas/login.html', success_redirect='/account/', merge=False): +def login(request, template_name='cas/login.html', success_redirect='/account/', **kwargs): + merge = kwargs.get('merge', False) logging.debug('CAS Provider Login view. Method is %s, merge is %s, template is %s.', request.method, merge, template_name) @@ -93,6 +94,15 @@ def login(request, template_name='cas/login.html', success_redirect='/account/', if not user.is_active: errors.append('This account is disabled.') else: + # Send the on_cas_login signal. If we get an HttpResponse, return that. + for receiver, response in signals.on_cas_login.send(sender=login, request=request, **kwargs): + if isinstance(response, HttpResponse): + return response + + if service is None: + # Try and pull the service off the session + service = request.session.pop('service', service) + if service is None: # Normal internal success redirection. logging.debug('Redirecting to %s', success_redirect) @@ -112,33 +122,6 @@ def login(request, template_name='cas/login.html', success_redirect='/account/', return render_to_response(template_name, {'form': form, 'errors': errors}, context_instance=RequestContext(request)) -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. - """ - user = request.user - user.backend = 'django.contrib.auth.backends.ModelBackend' - if 'service' in request.session: - service = request.session['service'] - del request.session['service'] - else: - service = '/' - errors = [] - if user is not None: - if user.is_active: - auth_login(request, user) - if service is not None: - ticket = create_service_ticket(user, service) - return HttpResponseRedirect(_build_service_url(service, ticket.ticket)) - else: - return HttpResponseRedirect(success_redirect) - else: - errors.append('This account is disabled.') - else: - errors.append('Incorrect username and/or password.') - return render_to_response(template_name, {'errors': errors}, context_instance=RequestContext(request)) - - def validate(request): service = request.GET.get('service', None) ticket_string = request.GET.get('ticket', None)