Created
August 5, 2015 13:19
-
-
Save bcardarella/6cd6854b2d3a1829b537 to your computer and use it in GitHub Desktop.
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
defmodule SogApi.Authenticator do | |
import Plug.Conn | |
def attempt_to_authenticate(conn, _) do | |
case find_account(conn) do | |
{ :ok, account } -> | |
assign(conn, :account, account) | |
:error -> | |
conn | |
|> send_resp(401, "") | |
|> halt | |
end | |
end | |
defp find_account(conn) do | |
account_id = conn | |
|> fetch_session | |
|> get_session(:account_id) | |
case SogApi.Repo.get(SogApi.Account, account_id) do | |
nil -> | |
:error | |
account -> | |
{ :ok, account } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment