diff --git a/lib/app_web/controllers/person_controller.ex b/lib/app_web/controllers/person_controller.ex index b2f906c6..4fa759cb 100644 --- a/lib/app_web/controllers/person_controller.ex +++ b/lib/app_web/controllers/person_controller.ex @@ -63,4 +63,10 @@ defmodule AppWeb.PersonController do def info(%{assigns: %{current_person: person}} = conn, _params) do render(conn, "info.html", person: person) end + + def logout(conn, _params) do + conn + |> AppWeb.Auth.logout() + |> redirect(to: Routes.page_path(conn, :index)) + end end diff --git a/lib/app_web/router.ex b/lib/app_web/router.ex index b2e5d9a6..4dccca6a 100644 --- a/lib/app_web/router.ex +++ b/lib/app_web/router.ex @@ -32,6 +32,7 @@ defmodule AppWeb.Router do # person information get "/people/info", PersonController, :info + get "/people/logout", PersonController, :logout # generic resources for schemas: resources "/items", ItemController diff --git a/lib/app_web/templates/person/info.html.eex b/lib/app_web/templates/person/info.html.eex index 551414cd..ded952d5 100644 --- a/lib/app_web/templates/person/info.html.eex +++ b/lib/app_web/templates/person/info.html.eex @@ -2,6 +2,8 @@ +Log out +

Hello <%= @person.givenName %>!

diff --git a/test/app_web/controllers/page_controller_test.exs b/test/app_web/controllers/page_controller_test.exs index be2fb57d..c4f82e8a 100644 --- a/test/app_web/controllers/page_controller_test.exs +++ b/test/app_web/controllers/page_controller_test.exs @@ -6,7 +6,7 @@ defmodule AppWeb.PageControllerTest do assert html_response(conn, 200) =~ "effectiveness" end - describe "login/register" do + describe "login/register and logout" do test "display error when password invalid", %{conn: conn} do params = %{"person" => %{"email" => "test@email.com", "password" => "p"}} conn = post(conn, Routes.page_path(conn, :register), params) @@ -14,13 +14,20 @@ defmodule AppWeb.PageControllerTest do assert html_response(conn, 200) =~ "should be at least 6 character(s)" end - test "redirects to home", %{conn: conn} do + test "redirects to user info page when already logged in", %{conn: conn} do params = %{"person" => %{"email" => "test@email.com", "password" => "password"}} conn = post(conn, Routes.page_path(conn, :register), params) assert redirected_to(conn, 302) =~ "/people/info" end + test "on logout redirect to index (ie / ) page", %{conn: conn} do + params = %{"person" => %{"email" => "test@email.com", "password" => "password"}} + conn = post(conn, Routes.page_path(conn, :register), params) + conn = get(conn, Routes.person_path(conn, :logout)) + assert redirected_to(conn, 302) =~ "/" + end end + end