changes
This commit is contained in:
parent
6a258db47f
commit
beaf92f7c4
22 changed files with 773 additions and 238 deletions
|
|
@ -0,0 +1,30 @@
|
|||
defmodule EzcontainerRailwayWeb.SessionController do
|
||||
use EzcontainerRailwayWeb, :controller
|
||||
|
||||
def token(conn, %{"railway_token" => token}) do
|
||||
case token_valid?(token) do
|
||||
true ->
|
||||
conn
|
||||
|> put_session(:railway_token, token)
|
||||
|> assign(:railway_token, token)
|
||||
|> redirect(to: "/containers")
|
||||
false ->
|
||||
conn
|
||||
|> put_flash(:error, "Invalid Token")
|
||||
|> redirect(to: "/")
|
||||
end
|
||||
end
|
||||
|
||||
defp token_valid?(token) do
|
||||
resp = EzcontainerRailway.Railway.get_projects(token).body
|
||||
|
||||
if has_errors?(resp["errors"]) do
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
defp has_errors?([_|_]), do: true
|
||||
defp has_errors?(_), do: false
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue