redirect login to 2fa check if active

This commit is contained in:
Hugh Rundle 2022-09-11 21:00:01 +10:00
parent 2ec343c5db
commit 8837495ffd

View file

@ -51,11 +51,25 @@ class Login(View):
# perform authentication
user = authenticate(request, username=username, password=password)
if user is not None:
# successful login
# if 2fa is set, don't log them in until they enter the right code
if user.two_factor_auth == True:
form = forms.Confirm2FAForm(request.GET, user)
return TemplateResponse(request, "two_factor_auth/two_factor_login.html", {"form": form, "2fa_user": user})
# otherwise, successful login
login(request, user)
user.update_active_date()
if request.POST.get("first_login"):
return set_language(user, redirect("get-started-profile"))
if user.two_factor_auth == None:
# set to false so this page doesn't pop up again
user.two_factor_auth = False
user.save(broadcast=False, update_fields=["two_factor_auth"])
# show the 2fa prompt page
return set_language(user, redirect("prompt-2fa"))
return set_language(user, redirect("/"))
# maybe the user is pending email confirmation
@ -70,7 +84,6 @@ class Login(View):
data = {"login_form": login_form, "register_form": register_form}
return TemplateResponse(request, "landing/login.html", data)
@method_decorator(login_required, name="dispatch")
class Logout(View):
"""log out"""