enforce token authorization
parent
64d49fea81
commit
088351899e
|
@ -11,6 +11,11 @@ defmodule WeatherTrackerWeb.WeatherConditionsController do
|
|||
def create(conn, params) do
|
||||
IO.inspect(params)
|
||||
|
||||
token =
|
||||
get_req_header(conn, "authorization")
|
||||
|> List.first()
|
||||
|
||||
if token == "shiqbNfVhL91JZOtqK0896BYJfZbUDrI2ERIzmoc" do
|
||||
case WeatherConditions.create_entry(params) do
|
||||
{:ok, weather_condition = %WeatherCondition{}} ->
|
||||
Logger.debug("Successfully created a weather condition entry")
|
||||
|
@ -26,5 +31,12 @@ defmodule WeatherTrackerWeb.WeatherConditionsController do
|
|||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{message: "Poorly formatted payload"})
|
||||
end
|
||||
else
|
||||
Logger.warn("No valid auth token provided")
|
||||
|
||||
conn
|
||||
|> put_status(:unprocessable_entity)
|
||||
|> json(%{message: "Auth token not valid"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue