Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. class UserLoginForm(forms.Form):
  2. email = forms.EmailField()
  3. password = forms.CharField(label='Password',
  4. widget=forms.PasswordInput)
  5.  
  6. class Meta:
  7. # model = User
  8. fields = ('email', 'password')
  9.  
  10. <form method="post" action="">
  11. {% for error in errors %}
  12. <p>{{ error }}</p>
  13. {% endfor %}
  14. {% csrf_token %}
  15. <input type="text" name="email" placeholder="Email" />
  16. <input type="password" name="password" placeholder="Password" />
  17. <input type="submit" value="Login" />
  18. </form>
  19.  
  20. def post(self, request, **kwargs):
  21. email = request.POST.get('email')
  22. password = request.POST.get('password')
  23. user = authenticate(email=email, password=password)
  24. if user is None:
  25. self.errors.append('Credentials are invalid')
  26. else:
  27. login(request, user)
  28. return super(LoginView, self).get(request, **kwargs)
  29.  
  30. class RegisterView(CreateView):
  31. template_name = 'users/register.html'
  32. form_class = UserCreationForm
  33. success_url = '/'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement