Commit 3033e3a9b1a1f75bc1c9f3a893719941f67adac1

Thomas de Grivel 2023-11-28T00:17:30

show user login on TOTP page

diff --git a/lib/kmxgit/user_manager/user.ex b/lib/kmxgit/user_manager/user.ex
index 5d73f2a..9c6a457 100644
--- a/lib/kmxgit/user_manager/user.ex
+++ b/lib/kmxgit/user_manager/user.ex
@@ -255,7 +255,7 @@ defmodule Kmxgit.UserManager.User do
   end
 
   def totp_verify(%__MODULE__{totp_secret: secret}, token) do
-    :pot.valid_totp(token, secret, [window: 1, addwindow: 1])
+    :pot.valid_totp(token, secret, [window: 2, addwindow: 2])
   end
 
   def totp_changeset(user, :delete) do
diff --git a/lib/kmxgit_web/controllers/user_session_controller.ex b/lib/kmxgit_web/controllers/user_session_controller.ex
index 95ada98..336a73c 100644
--- a/lib/kmxgit_web/controllers/user_session_controller.ex
+++ b/lib/kmxgit_web/controllers/user_session_controller.ex
@@ -42,6 +42,7 @@ defmodule KmxgitWeb.UserSessionController do
         |> assign(:changeset, changeset)
         |> assign(:error_message, "Invalid token")
         |> assign(:totp, totp)
+        |> assign(:user, user)
         |> render("totp.html")
       end
     else
diff --git a/lib/kmxgit_web/templates/user_session/totp.html.heex b/lib/kmxgit_web/templates/user_session/totp.html.heex
index 875ce39..a28df7c 100644
--- a/lib/kmxgit_web/templates/user_session/totp.html.heex
+++ b/lib/kmxgit_web/templates/user_session/totp.html.heex
@@ -9,7 +9,8 @@
     <% end %>
 
     <div class="mb-3">
-      <%= label f, :totp, gettext("TOTP (Google Authenticator)"), class: "form-label" %>
+      <%= label f, :totp, gettext("TOTP (Google Authenticator) for user %{user}",
+          %{user: @user.login}), class: "form-label" %>
       <%= number_input f, :totp, class: "form-control" %>
       <%= error_tag f, :totp %>
     </div>