Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2012 18:04
Show Gist options
  • Save anonymous/3641465 to your computer and use it in GitHub Desktop.
Save anonymous/3641465 to your computer and use it in GitHub Desktop.
login form
class LoginForm(forms.Form):
username = forms.CharField(label="Username", max_length=30)
password = forms.CharField(label="Password", widget=forms.PasswordInput)
@property
def helper(self):
form = LoginForm()
helper = FormHelper()
reset = Reset('','Reset')
helper.add_input(reset)
submit = Submit('','Log In')
helper.add_input(submit)
helper.form_action = '/accounts/login'
helper.form_method = 'POST'
return helper
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
if username and password:
self.user_cache = authenticate(username=username, password=password)
if self.user_cache is None:
raise forms.ValidationError("Please enter a correct username and password. Note that both fields are case-sensitive.")
elif not self.user_cache.is_active:
raise forms.ValidationError("This account is inactive.")
return self.cleaned_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment