From 8837495ffd13b806051e0049b1bf32d924cbda85 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 11 Sep 2022 21:00:01 +1000 Subject: [PATCH] redirect login to 2fa check if active --- bookwyrm/views/landing/login.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/landing/login.py b/bookwyrm/views/landing/login.py index 98a2b6e61..0c8d596d6 100644 --- a/bookwyrm/views/landing/login.py +++ b/bookwyrm/views/landing/login.py @@ -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"""