2022-07-23 01:44:03 +02:00
|
|
|
defmodule ClaperWeb.UserLiveAuth do
|
|
|
|
|
import Phoenix.LiveView
|
2023-04-20 17:15:31 +02:00
|
|
|
import Phoenix.Component
|
2024-04-06 11:48:47 +02:00
|
|
|
|
|
|
|
|
use Phoenix.VerifiedRoutes,
|
|
|
|
|
endpoint: ClaperWeb.Endpoint,
|
|
|
|
|
router: ClaperWeb.Router
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
def on_mount(:default, _params, %{"current_user" => current_user} = _session, socket) do
|
2024-10-20 11:13:31 +02:00
|
|
|
socket = assign_new(socket, :current_user, fn -> current_user end)
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-10-20 11:13:31 +02:00
|
|
|
cond do
|
|
|
|
|
not Application.get_env(:claper, :email_confirmation) ->
|
|
|
|
|
{:cont, socket}
|
2022-09-05 12:01:30 +02:00
|
|
|
|
2024-10-20 11:13:31 +02:00
|
|
|
current_user.confirmed_at ->
|
|
|
|
|
{:cont, socket}
|
2022-09-05 12:01:30 +02:00
|
|
|
|
2024-10-20 11:13:31 +02:00
|
|
|
true ->
|
|
|
|
|
{:halt, redirect(socket, to: ~p"/users/register/confirm")}
|
|
|
|
|
end
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def on_mount(:default, _params, _session, socket),
|
2024-04-06 11:48:47 +02:00
|
|
|
do: {:halt, redirect(socket, to: ~p"/users/register/confirm")}
|
2022-07-23 01:44:03 +02:00
|
|
|
end
|