memEx/lib/lokal_web/controllers/user_session_controller.ex

27 lines
748 B
Elixir
Raw Normal View History

2021-03-11 21:12:55 -05:00
defmodule LokalWeb.UserSessionController do
use LokalWeb, :controller
alias Lokal.Accounts
alias LokalWeb.UserAuth
def new(conn, _params) do
2022-02-25 21:53:04 -05:00
render(conn, "new.html", error_message: nil, page_title: gettext("Log in"))
2021-03-11 21:12:55 -05:00
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
2022-02-25 21:53:04 -05:00
render(conn, "new.html", error_message: dgettext("errors", "Invalid email or password"))
2021-03-11 21:12:55 -05:00
end
end
def delete(conn, _params) do
conn
2022-02-25 21:53:04 -05:00
|> put_flash(:info, dgettext("prompts", "Logged out successfully."))
2021-03-11 21:12:55 -05:00
|> UserAuth.log_out_user()
end
end