only update usage counters on valid TOTP (fixes philomena-dev/philomena#50)

This commit is contained in:
byte[] 2020-10-23 00:26:49 -04:00
parent c30c8e3136
commit 1e2c57d8e8

View file

@ -124,7 +124,16 @@ defmodule PhilomenaWeb.UserAuth do
user = user_token && Users.get_user_by_session_token(user_token)
totp = totp_token && Users.user_totp_token_valid?(user, totp_token)
if user, do: update_usages(conn, user)
cond do
user && user.otp_required_for_login && totp ->
update_usages(conn, user)
user && !user.otp_required_for_login ->
update_usages(conn, user)
true ->
nil
end
conn
|> assign(:current_user, user)