Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. class UserLoginForm(forms.Form):
  2. username = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Username'}))
  3. password = forms.CharField(widget=forms.PasswordInput(attrs={'class':'form-control','placeholder':'Password'}))
  4. youfield = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','placeholder':'yourfield'}))
  5. def clean(self, *args, **kwargs):
  6. username = self.cleaned_data.get("username")
  7. password = self.cleaned_data.get("password")
  8.  
  9. #user_qs = User.objects.filter(username=username)
  10. #if user_qs.count() == 1:
  11. # user = user_qs.first()
  12. if username and password:
  13. user = authenticate(username=username, password=password)
  14. if not user:
  15. raise forms.ValidationError("This user does not exist")
  16. if not user.check_password(password):
  17. raise forms.ValidationError("Incorrect password")
  18. if not user.is_active:
  19. raise forms.ValidationError("This user is no longer active")
  20. return super(UserLoginForm, self).clean(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement