Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserLoginForm(forms.Form):
- email = forms.EmailField()
- password = forms.CharField(label='Password',
- widget=forms.PasswordInput)
- class Meta:
- # model = User
- fields = ('email', 'password')
- <form method="post" action="">
- {% for error in errors %}
- <p>{{ error }}</p>
- {% endfor %}
- {% csrf_token %}
- <input type="text" name="email" placeholder="Email" />
- <input type="password" name="password" placeholder="Password" />
- <input type="submit" value="Login" />
- </form>
- def post(self, request, **kwargs):
- email = request.POST.get('email')
- password = request.POST.get('password')
- user = authenticate(email=email, password=password)
- if user is None:
- self.errors.append('Credentials are invalid')
- else:
- login(request, user)
- return super(LoginView, self).get(request, **kwargs)
- class RegisterView(CreateView):
- template_name = 'users/register.html'
- form_class = UserCreationForm
- success_url = '/'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement