Corrected behavior of merge/login forms on GET requests.
authordeyk <deyk@crossway.org>
Wed, 18 Jan 2012 21:40:29 +0000 (13:40 -0800)
committerdeyk <deyk@crossway.org>
Wed, 18 Jan 2012 21:40:29 +0000 (13:40 -0800)
cas_provider/forms.py
cas_provider/models.py
cas_provider/views.py

index 8a1452a..f40d18c 100644 (file)
@@ -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)
     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):
     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',
 
     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:
         try:
             login_ticket = LoginTicket.objects.get(ticket=lt)
         except:
index 94023b7..39641a1 100644 (file)
@@ -1,6 +1,7 @@
 from django.db import models
 from django.contrib.auth.models import User
 
 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)
 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)
     
     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):
 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)
index 5d9ea38..526a100 100644 (file)
@@ -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.')
                     errors.append('This account is disabled.')
             else:
                     errors.append('Incorrect username and/or password.')
+    else:
         if merge:
         if merge:
-            form = MergeLoginForm(request.GET, request=request)
+            form = MergeLoginForm(initial={'service': service, 'email': request.GET.get('email')})
         else:
         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))
 
     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.
 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.