replace coherence with guardian

This commit is contained in:
Thomas Citharel
2017-12-09 14:58:37 +01:00
parent 90ceb4f6fe
commit 8ac705d8c2
52 changed files with 208 additions and 1254 deletions

View File

@@ -0,0 +1,27 @@
defmodule EventosWeb.SessionController do
use EventosWeb, :controller
alias Eventos.Accounts.User
alias Eventos.Accounts
def sign_in(conn, %{"email" => email, "password" => password}) do
with %User{} = user <- Accounts.find(email) do
# Attempt to authenticate the user
with {:ok, token, _claims} <- Accounts.authenticate(%{user: user, password: password}) do
# Render the token
render conn, "token.json", token: token
end
end
end
def sign_out(conn, _params) do
conn
|> Eventos.Guardian.Plug.sign_out()
|> send_resp(204, "")
end
def show(conn, _params) do
user = Eventos.Guardian.Plug.current_resource(conn)
send_resp(conn, 200, Poison.encode!(%{user: user}))
end
end