-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
61cb6ee
commit 66b362c
Showing
8 changed files
with
70 additions
and
5 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
File renamed without changes.
File renamed without changes.
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,41 @@ | ||
defmodule Systems.Account.Plug do | ||
@behaviour Plug | ||
|
||
import Plug.Conn | ||
alias Systems.Account | ||
|
||
@valid_participant_path ~r"^\/assignment\/\d.*$" | ||
|
||
@impl true | ||
def init(opts), do: opts | ||
|
||
@impl true | ||
def call(conn, _opts) do | ||
case current_user(conn) do | ||
{:ok, %{} = user} -> | ||
external? = Account.Public.external?(user) | ||
signof_if_needed(conn, external?) | ||
|
||
_ -> | ||
conn | ||
end | ||
end | ||
|
||
defp current_user(conn) do | ||
if user_token = get_session(conn, :user_token) do | ||
{:ok, Account.Public.get_user_by_session_token(user_token)} | ||
else | ||
{:error, :no_user_token} | ||
end | ||
end | ||
|
||
defp signof_if_needed(%{request_path: request_path} = conn, true) do | ||
if Regex.match?(@valid_participant_path, request_path) do | ||
conn | ||
else | ||
Account.UserAuth.forget_user(conn) | ||
end | ||
end | ||
|
||
defp signof_if_needed(conn, _), do: conn | ||
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