From 3a1060826f145b6cba0a68db6a97547771da25fd Mon Sep 17 00:00:00 2001 From: Harshad Sharma Date: Mon, 13 May 2024 23:05:09 +0530 Subject: [PATCH] Add home live beind login --- lib/freedive_web/components/layouts/app.html.heex | 14 +++++++------- lib/freedive_web/live/home_live.ex | 15 +++++++++++++++ lib/freedive_web/router.ex | 3 ++- .../controllers/page_controller_test.exs | 2 +- .../live/user_confirmation_live_test.exs | 12 ++++++++++-- 5 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 lib/freedive_web/live/home_live.ex diff --git a/lib/freedive_web/components/layouts/app.html.heex b/lib/freedive_web/components/layouts/app.html.heex index b0299ad..ed5f9da 100644 --- a/lib/freedive_web/components/layouts/app.html.heex +++ b/lib/freedive_web/components/layouts/app.html.heex @@ -58,24 +58,24 @@ <%= @current_user.email %> - <%!-- <.navbar_item has-dropdown is-hoverable> + <.navbar_item has-dropdown is-hoverable> <.navbar_link> System <.navbar_dropdown> - <.navbar_item> + <%!-- <.navbar_item> <.link>Software Updates <.navbar_divider /> <.navbar_item> <.link>Packages - - <.navbar_item> - <.link>Services - + --%> + <.link href={~p"/services"} class="navbar-item"> + Services + - --%> + <% end %> <.navbar_item has-dropdown is-hoverable> <.navbar_link> diff --git a/lib/freedive_web/live/home_live.ex b/lib/freedive_web/live/home_live.ex new file mode 100644 index 0000000..eade311 --- /dev/null +++ b/lib/freedive_web/live/home_live.ex @@ -0,0 +1,15 @@ +defmodule FreediveWeb.HomeLive do + use FreediveWeb, :live_view + + def render(assigns) do + ~H""" + <.section> + <.title>Home + + """ + end + + def mount(_params, _session, socket) do + {:ok, socket} + end +end diff --git a/lib/freedive_web/router.ex b/lib/freedive_web/router.ex index 4744460..afa1895 100644 --- a/lib/freedive_web/router.ex +++ b/lib/freedive_web/router.ex @@ -20,7 +20,7 @@ defmodule FreediveWeb.Router do scope "/", FreediveWeb do pipe_through :browser - get "/", PageController, :home + # get "/", PageController, :home end # Other scopes may use custom stacks. @@ -68,6 +68,7 @@ defmodule FreediveWeb.Router do live_session :require_authenticated_user, on_mount: [{FreediveWeb.UserAuth, :ensure_authenticated}] do + live "/", HomeLive live "/users/settings", UserSettingsLive, :edit live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email end diff --git a/test/freedive_web/controllers/page_controller_test.exs b/test/freedive_web/controllers/page_controller_test.exs index 1c0b7dd..3ece5d1 100644 --- a/test/freedive_web/controllers/page_controller_test.exs +++ b/test/freedive_web/controllers/page_controller_test.exs @@ -3,6 +3,6 @@ defmodule FreediveWeb.PageControllerTest do test "GET /", %{conn: conn} do conn = get(conn, ~p"/") - assert html_response(conn, 200) =~ "Under Construction" + assert html_response(conn, 302) =~ "redirected" end end diff --git a/test/freedive_web/live/user_confirmation_live_test.exs b/test/freedive_web/live/user_confirmation_live_test.exs index 8e25bf0..824d4e3 100644 --- a/test/freedive_web/live/user_confirmation_live_test.exs +++ b/test/freedive_web/live/user_confirmation_live_test.exs @@ -51,8 +51,12 @@ defmodule FreediveWeb.UserConfirmationLiveTest do assert {:ok, conn} = result + # Home is now behind login page and only latest flash message is shown assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "User confirmation link is invalid or it has expired" + "You must log in to access this page." + + # assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + # "User confirmation link is invalid or it has expired" # when logged in conn = @@ -80,8 +84,12 @@ defmodule FreediveWeb.UserConfirmationLiveTest do |> render_submit() |> follow_redirect(conn, ~p"/") + # Home is now behind login page and only latest flash message is shown assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ - "User confirmation link is invalid or it has expired" + "You must log in to access this page." + + # assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ + # "User confirmation link is invalid or it has expired" refute Accounts.get_user!(user.id).confirmed_at end