Change models, new migrations, fix front and make tests work

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-13 23:33:03 +01:00
parent 92d2045735
commit 20cd1bb579
186 changed files with 2982 additions and 3214 deletions

View File

@@ -0,0 +1,28 @@
defmodule EventosWeb.UserSessionController do
use EventosWeb, :controller
alias Eventos.Accounts.User
alias Eventos.Accounts
import Logger
def sign_in(conn, %{"email" => email, "password" => password}) do
case Accounts.find_by_email(email) do
%User{} = user ->
# Attempt to authenticate the user
case Accounts.authenticate(%{user: user, password: password}) do
{:ok, token, _claims} ->
# Render the token
render conn, "token.json", %{token: token, user: user}
_ ->
send_resp(conn, 400, Poison.encode!(%{"error_msg" => "Bad login", "display_error" => "session.error.bad_login", "error_code" => 400}))
end
_ ->
send_resp(conn, 400, Poison.encode!(%{"error_msg" => "No such user", "display_error" => "session.error.bad_login", "error_code" => 400}))
end
end
def sign_out(conn, _params) do
conn
|> Guardian.Plug.sign_out()
|> send_resp(204, "")
end
end