fix(otp): redirect to setup otp

This commit is contained in:
zuk 2024-10-20 12:11:51 +02:00
parent 2ca8ba1398
commit 76cde52404
3 changed files with 11 additions and 3 deletions

View file

@ -3,3 +3,8 @@
--accent-bg: #bab3ab;
--bg: #f6f5f4;
}
/* hide hidden things in flexbox */
[hidden] {
display: none;
}

View file

@ -14,9 +14,10 @@ class UserConnectionForm(forms.ModelForm):
@login_required
@otp_required
def list_connections(request: HttpRequest):
user = request.user
if not user.is_verified():
return redirect("two_factor:setup")
if request.method == "POST":
form = UserConnectionForm(request.POST)
if form.is_valid():
@ -39,9 +40,9 @@ def list_connections(request: HttpRequest):
return render(request, "connection_list.html", context={"connections": connections, "form": form})
@login_required
@otp_required
def toggle_connection(request: HttpRequest, connection_id: int):
if request.method != "POST" or "state" not in request.POST:
return HttpResponseBadRequest()
if request.POST["state"] not in ["enabled", "disabled"]:
@ -58,7 +59,7 @@ def toggle_connection(request: HttpRequest, connection_id: int):
return redirect("connections_list")
@login_required
# @login_required
@otp_required
def delete_connection(request: HttpRequest, connection_id: int):
connection = get_object_or_404(UserConnection, pk=connection_id)

View file

@ -143,6 +143,8 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGOUT_REDIRECT_URL = "connections_list"
LOGIN_URL = "two_factor:login"
# 15 days
TWO_FACTOR_REMEMBER_COOKIE_AGE = 1296000
# this one is optional
# LOGIN_REDIRECT_URL = 'two_factor:profile'
STATIC_ROOT = BASE_DIR / "static"