bones73k/lib/real_estate_web/controllers/user_session_controller.ex
Joao Gilberto Balsini Moura b6524131c1 Add a way to force user logout
The idea is to remove the session and also disconnect all liveviews
2020-09-28 06:06:15 -03:00

35 lines
900 B
Elixir

defmodule RealEstateWeb.UserSessionController do
use RealEstateWeb, :controller
alias RealEstate.Accounts
alias RealEstateWeb.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
def force_logout(conn, _params) do
conn
|> put_flash(
:info,
"You were logged out. Please login again to continue using our application."
)
|> UserAuth.log_out_user()
end
end