Include register form in return login page

in case of wrong password
This commit is contained in:
Mouse Reeve 2020-03-22 11:20:36 -07:00
parent 3a0a87bee0
commit eac8f2a2f9

View file

@ -16,18 +16,27 @@ def user_login(request):
if request.method == 'GET':
return redirect('/login')
form = forms.LoginForm(request.POST)
if not form.is_valid():
return TemplateResponse(request, 'login.html', {'login_form': form})
register_form = forms.RegisterForm()
login_form = forms.LoginForm(request.POST)
if not login_form.is_valid():
return TemplateResponse(
request,
'login.html',
{'login_form': login_form, 'register_form': register_form}
)
username = form.data['username']
username = login_form.data['username']
username = '%s@%s' % (username, DOMAIN)
password = form.data['password']
password = login_form.data['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect(request.GET.get('next', '/'))
return TemplateResponse(request, 'login.html', {'login_form': form})
return TemplateResponse(
request,
'login.html',
{'login_form': login_form, 'register_form': register_form}
)
def register(request):