From: deyk Date: Wed, 18 Jan 2012 21:40:29 +0000 (-0800) Subject: Corrected behavior of merge/login forms on GET requests. X-Git-Tag: 22.4~58 X-Git-Url: https://git.mdrn.pl/django-cas-provider.git/commitdiff_plain/36da57ccf1745c118c112fe457a173293e74ad36?ds=sidebyside Corrected behavior of merge/login forms on GET requests. --- diff --git a/cas_provider/forms.py b/cas_provider/forms.py index 8a1452a..f40d18c 100644 --- a/cas_provider/forms.py +++ b/cas_provider/forms.py @@ -11,7 +11,7 @@ class LoginForm(forms.Form): password = forms.CharField(widget=forms.PasswordInput) #warn = forms.BooleanField(required=False) # TODO: Implement lt = forms.CharField(widget=forms.HiddenInput, initial=create_login_ticket, required=False) - service = forms.CharField(widget=forms.HiddenInput, initial='', required=False) + service = forms.CharField(widget=forms.HiddenInput, required=False) remember_me = forms.BooleanField(required=False) def __init__(self, *args, **kwargs): @@ -28,8 +28,9 @@ class LoginForm(forms.Form): def clean_lt(self): lt = self.cleaned_data.get('lt', - self.initial.get('lt', - self.fields['lt'].initial())) + self.initial.get('lt', None)) + if lt is None: + lt = self.fields['lt'].initial() try: login_ticket = LoginTicket.objects.get(ticket=lt) except: diff --git a/cas_provider/models.py b/cas_provider/models.py index 94023b7..39641a1 100644 --- a/cas_provider/models.py +++ b/cas_provider/models.py @@ -1,6 +1,7 @@ from django.db import models from django.contrib.auth.models import User + class ServiceTicket(models.Model): user = models.ForeignKey(User) service = models.URLField(verify_exists=False) @@ -9,10 +10,11 @@ class ServiceTicket(models.Model): def __unicode__(self): return "%s (%s) - %s" % (self.user.username, self.service, self.created) - + + class LoginTicket(models.Model): ticket = models.CharField(max_length=32) created = models.DateTimeField(auto_now=True) def __unicode__(self): - return "%s - %s" % (self.ticket, self.created) \ No newline at end of file + return "%s - %s" % (self.ticket, self.created) diff --git a/cas_provider/views.py b/cas_provider/views.py index 5d9ea38..526a100 100644 --- a/cas_provider/views.py +++ b/cas_provider/views.py @@ -73,15 +73,14 @@ def login(request, template_name='cas/login.html', success_redirect='/account/', errors.append('This account is disabled.') else: errors.append('Incorrect username and/or password.') + else: if merge: - form = MergeLoginForm(request.GET, request=request) + form = MergeLoginForm(initial={'service': service, 'email': request.GET.get('email')}) else: - form = LoginForm(request.GET, request=request) - else: - form = LoginForm(service) - + form = LoginForm(initial={'service': service}) 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.