meta/lib/recycledcloud_web/controllers/user_session_controller.ex
Timothée Floure 56d2d5bccf
Run mix phx.gen.auth Accounts User users
Uses phx_gen_auth as a scaffold to build our own logic.
2020-12-15 14:24:14 +01:00

26 lines
708 B
Elixir

defmodule RecycledCloudWeb.UserSessionController do
use RecycledCloudWeb, :controller
alias RecycledCloud.Accounts
alias RecycledCloudWeb.UserAuth
def new(conn, _params) do
render(conn, "new.html", error_message: nil)
end
def create(conn, %{"user" => user_params}) do
%{"email" => email, "password" => password} = user_params
if user = Accounts.get_user_by_email_and_password(email, password) do
UserAuth.log_in_user(conn, user, user_params)
else
render(conn, "new.html", error_message: "Invalid email or password")
end
end
def delete(conn, _params) do
conn
|> put_flash(:info, "Logged out successfully.")
|> UserAuth.log_out_user()
end
end