Skip to content

Instantly share code, notes, and snippets.

@pyaf
Created March 24, 2017 12:15
Show Gist options
  • Save pyaf/4595d81fc9ba595a14aa62655a96948b to your computer and use it in GitHub Desktop.
Save pyaf/4595d81fc9ba595a14aa62655a96948b to your computer and use it in GitHub Desktop.
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField()
class Meta:
fields = ['username','password']
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if not user:
raise forms.ValidationError("Sorry, that login was invalid. Please try again.")
return self.cleaned_data
def login(self, request):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
user = authenticate(username=username, password=password)
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment