mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
re-add usage tracker
This commit is contained in:
parent
70f530cb76
commit
78dac4df70
1 changed files with 12 additions and 0 deletions
|
@ -4,6 +4,8 @@ defmodule PhilomenaWeb.UserAuth do
|
|||
|
||||
alias Philomena.Users
|
||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||
alias PhilomenaWeb.UserIpUpdater
|
||||
alias PhilomenaWeb.UserFingerprintUpdater
|
||||
|
||||
# Make the remember me cookie valid for 365 days.
|
||||
# If you want bump or reduce this value, also change
|
||||
|
@ -122,6 +124,8 @@ 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)
|
||||
|
||||
conn
|
||||
|> assign(:current_user, user)
|
||||
|> assign(:totp_valid?, totp)
|
||||
|
@ -193,4 +197,12 @@ defmodule PhilomenaWeb.UserAuth do
|
|||
defp maybe_store_return_to(conn), do: conn
|
||||
|
||||
defp signed_in_path(_conn), do: "/"
|
||||
|
||||
defp update_usages(conn, user) do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
conn = fetch_cookies(conn)
|
||||
|
||||
UserIpUpdater.cast(user.id, conn.remote_ip, now)
|
||||
UserFingerprintUpdater.cast(user.id, conn.cookies["_ses"], now)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue