-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Implement token-based sessions (#4463)"
This reverts commit 373d4dd.
- Loading branch information
Showing
33 changed files
with
364 additions
and
879 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule PlausibleWeb.LastSeenPlug do | ||
import Plug.Conn | ||
use Plausible.Repo | ||
|
||
@one_hour 60 * 60 | ||
|
||
def init(opts) do | ||
opts | ||
end | ||
|
||
def call(conn, _opts) do | ||
last_seen = get_session(conn, :last_seen) | ||
user = conn.assigns[:current_user] | ||
|
||
cond do | ||
user && last_seen && last_seen < unix_now() - @one_hour -> | ||
persist_last_seen(user) | ||
put_session(conn, :last_seen, unix_now()) | ||
|
||
user && !last_seen -> | ||
put_session(conn, :last_seen, unix_now()) | ||
|
||
true -> | ||
conn | ||
end | ||
end | ||
|
||
defp persist_last_seen(user) do | ||
q = from(u in Plausible.Auth.User, where: u.id == ^user.id) | ||
|
||
Repo.update_all(q, set: [last_seen: DateTime.utc_now()]) | ||
end | ||
|
||
defp unix_now do | ||
DateTime.utc_now() |> DateTime.to_unix() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
defmodule PlausibleWeb.SuperAdminOnlyPlug do | ||
@moduledoc false | ||
|
||
use Plausible.Repo | ||
|
||
import Plug.Conn | ||
use Plausible.Repo | ||
|
||
def init(options) do | ||
options | ||
end | ||
|
||
def call(conn, _opts) do | ||
current_user = conn.assigns[:current_user] | ||
|
||
if current_user && Plausible.Auth.is_super_admin?(current_user) do | ||
conn | ||
with {:ok, user} <- PlausibleWeb.UserAuth.get_user(conn), | ||
true <- Plausible.Auth.is_super_admin?(user) do | ||
assign(conn, :current_user, user) | ||
else | ||
conn | ||
|> PlausibleWeb.UserAuth.log_out_user() | ||
|> send_resp(403, "Not allowed") | ||
|> halt() | ||
_ -> | ||
conn |> send_resp(403, "Not allowed") |> halt | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.