1 from django import forms
2 from django.contrib.auth.forms import AuthenticationForm
3 from django.contrib.auth import authenticate
5 from models import ServiceTicket, LoginTicket
6 from utils import create_login_ticket
9 class LoginForm(forms.Form):
10 email = forms.CharField(max_length=255)
11 password = forms.CharField(widget=forms.PasswordInput)
12 #warn = forms.BooleanField(required=False) # TODO: Implement
13 lt = forms.CharField(widget=forms.HiddenInput, initial=create_login_ticket, required=False)
14 service = forms.CharField(widget=forms.HiddenInput, initial='', required=False)
15 remember_me = forms.BooleanField(required=False)
17 def __init__(self, *args, **kwargs):
18 # renew = kwargs.pop('renew', None)
19 # gateway = kwargs.pop('gateway', None)
20 request = kwargs.pop('request', None)
21 super(LoginForm, self).__init__(*args, **kwargs)
22 self.request = request
24 def clean_remember_me(self):
25 remember = self.cleaned_data['remember_me']
26 if not remember and self.request is not None:
27 self.request.session.set_expiry(0)
30 lt = self.cleaned_data.get('lt',
31 self.initial.get('lt',
32 self.fields['lt'].initial()))
34 login_ticket = LoginTicket.objects.get(ticket=lt)
36 raise forms.ValidationError("Login ticket expired. Please try again.")
41 class MergeLoginForm(LoginForm):
42 email = forms.CharField(max_length=255, widget=forms.HiddenInput)