1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2025-01-23 17:18:36 +00:00
mobilizon/lib/eventos_web/controllers/session_controller.ex

27 lines
750 B
Elixir
Raw Normal View History

2017-12-09 13:58:37 +00:00
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