2021-08-11 06:57:23 +00:00
|
|
|
defmodule KetbinWeb.UserSessionController do
|
|
|
|
use KetbinWeb, :controller
|
|
|
|
|
|
|
|
alias Ketbin.Accounts
|
|
|
|
alias KetbinWeb.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()
|
2021-10-07 00:12:24 +00:00
|
|
|
|
|
|
|
conn
|
2021-08-11 06:57:23 +00:00
|
|
|
end
|
|
|
|
end
|