1 from django import forms
2 from django.conf import settings
3 from django.contrib.auth import authenticate
4 from django.contrib.auth.forms import AuthenticationForm
5 from django.forms import ValidationError
6 from django.utils.translation import ugettext_lazy as _
7 from models import LoginTicket
11 __all__ = ['LoginForm', ]
14 class LoginForm(AuthenticationForm):
15 lt = forms.CharField(widget=forms.HiddenInput)
16 service = forms.CharField(widget=forms.HiddenInput, required=False)
19 ticket = self.cleaned_data['lt']
20 timeframe = datetime.datetime.now() - \
21 datetime.timedelta(minutes=settings.CAS_TICKET_EXPIRATION)
23 return LoginTicket.objects.get(ticket=ticket, created__gte=timeframe)
24 except LoginTicket.DoesNotExist:
25 raise ValidationError(_('Login ticket expired. Please try again.'))
29 super(LoginForm, self).clean(self)
30 self.cleaned_data.get('lt').delete()
31 return self.cleaned_data
35 for k, error in self.errors.items():
36 errors += [e for e in error]