Fixed faulty redirect if user is already logged in. Added some better logging.
[django-cas-provider.git] / cas_provider / forms.py
1 from django import forms
2 from django.contrib.auth.forms import AuthenticationForm
3 from django.contrib.auth import authenticate
4
5
6 class LoginForm(forms.Form):
7     email = forms.CharField(max_length=255)
8     password = forms.CharField(widget=forms.PasswordInput)
9     service = forms.CharField(widget=forms.HiddenInput, required=False)
10     remember_me = forms.BooleanField(required=False, label="Keep me signed in", widget=forms.CheckboxInput(attrs={'class':'remember_me'}))
11
12     def __init__(self, *args, **kwargs):
13         # renew = kwargs.pop('renew', None)
14         # gateway = kwargs.pop('gateway', None)
15         request = kwargs.pop('request', None)
16         super(LoginForm, self).__init__(*args, **kwargs)
17         self.request = request
18
19     def clean_remember_me(self):
20         remember = self.cleaned_data['remember_me']
21         if not remember and self.request is not None:
22             self.request.session.set_expiry(0)
23             
24
25 class MergeLoginForm(LoginForm):
26     email = forms.CharField(max_length=255, widget=forms.HiddenInput)