Created
March 3, 2014 13:51
-
-
Save jschoch/9325310 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 Check do | |
require Lager | |
use Phoenix.Controller | |
def authed?(conn,f) do | |
try do | |
user = get_user_for_request(conn) | |
token = get_token_for_request(conn) | |
if (token != "xxx1xxx") do | |
Lager.error "bad token error" | |
raise "bad Token" | |
else | |
f.(conn) | |
end | |
rescue | |
error -> | |
Lager.info "authed? raised error #{inspect error}" | |
text conn, 401, "Unauthorized" | |
end | |
end | |
def get_user_for_request(conn) do | |
#todo lookup user from header | |
:foo | |
end | |
def get_token_for_request(conn) do | |
#todo put this in the header | |
token = conn.params["token"] | |
case token do | |
nil -> raise "No Token" | |
token -> token | |
end | |
Lager.info "checking token #{inspect token}" | |
token | |
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
defmodule Cntrl do | |
use Phoenix.Controller | |
require Lager | |
def do_something(conn) do | |
f = fn(conn) -> | |
#do some stuff | |
text conn, "win" | |
end | |
Check.authed?(conn,f) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment