Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logout link on user info page #49

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/app_web/controllers/person_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/app_web/templates/person/info.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<img class="br-100 fl " width="32px" src="<%= @person.picture %>" />
</a>

<a class="db tr pointer dwyl-teal" href="<%= Routes.person_path(@conn, :logout) %>">Log out</a>

<section>
<h1 class="tc mid-grey"> Hello <%= @person.givenName %>!</h1>
<p class="tc f4">
Expand Down
11 changes: 9 additions & 2 deletions test/app_web/controllers/page_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ 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" => "[email protected]", "password" => "p"}}
conn = post(conn, Routes.page_path(conn, :register), params)

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" => "[email protected]", "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" => "[email protected]", "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