Created
March 24, 2017 12:15
-
-
Save pyaf/4595d81fc9ba595a14aa62655a96948b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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