Hooked up token_protected_route plug to database
This commit is contained in:
parent
bac51152d6
commit
48d84d76cd
1 changed files with 15 additions and 7 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
defmodule PinchflatWeb.Plugs do
|
defmodule PinchflatWeb.Plugs do
|
||||||
use PinchflatWeb, :router
|
|
||||||
|
|
||||||
# TODO: doc and test
|
# TODO: doc and test
|
||||||
|
use PinchflatWeb, :router
|
||||||
|
alias Pinchflat.Settings
|
||||||
|
|
||||||
def maybe_basic_auth(conn, opts) do
|
def maybe_basic_auth(conn, opts) do
|
||||||
if Application.get_env(:pinchflat, :expose_feed_endpoints) do
|
if Application.get_env(:pinchflat, :expose_feed_endpoints) do
|
||||||
conn
|
conn
|
||||||
|
|
@ -26,17 +27,24 @@ defmodule PinchflatWeb.Plugs do
|
||||||
end
|
end
|
||||||
|
|
||||||
def token_protected_route(%{query_params: %{"route_token" => route_token}} = conn, _opts) do
|
def token_protected_route(%{query_params: %{"route_token" => route_token}} = conn, _opts) do
|
||||||
# TODO: make this match against the token in the database
|
if Settings.get!(:route_token) == route_token do
|
||||||
conn
|
conn
|
||||||
|
else
|
||||||
|
send_unauthorized(conn)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def token_protected_route(conn, _opts) do
|
def token_protected_route(conn, _opts) do
|
||||||
conn
|
send_unauthorized(conn)
|
||||||
|> send_resp(:unauthorized, "Unauthorized")
|
|
||||||
|> halt()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp credential_set?(credential) do
|
defp credential_set?(credential) do
|
||||||
credential && credential != ""
|
credential && credential != ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp send_unauthorized(conn) do
|
||||||
|
conn
|
||||||
|
|> send_resp(:unauthorized, "Unauthorized")
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue