class LoginFormView FormView form_class UserLoginForm success_url temp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class LoginFormView(FormView):
form_class = UserLoginForm
success_url = '/'
template_name = 'login.html'
def form_valid(self, form):
return super(LoginFormView, self).form_valid(form)
def form_invalid(self, form, **kwargs):
return super(LoginFormView, self).form_invalid(form)
def post(self, request, *args, **kwargs):
email = request.POST['email']
password = request.POST['password']
user = authenticate(email=email, password=password)
if user is not None:
login(request=request, user=user)
return redirect('/')
else:
return self.form_invalid(form, **kwargs)