Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserLoginForm(forms.Form):
- username = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Username'}))
- password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'Password'}))
- youfield = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'yourfield'}))
- def clean(self, *args, **kwargs):
- username = self.cleaned_data.get("username")
- password = self.cleaned_data.get("password")
- #user_qs = User.objects.filter(username=username)
- #if user_qs.count() == 1:
- # user = user_qs.first()
- if username and password:
- user = authenticate(username=username, password=password)
- if not user:
- raise forms.ValidationError("This user does not exist")
- if not user.check_password(password):
- raise forms.ValidationError("Incorrect password")
- if not user.is_active:
- raise forms.ValidationError("This user is no longer active")
- return super(UserLoginForm, self).clean(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement