-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Bug fix: show logout template after logging out (#2913)
1 parent
513935c
commit a8d5786
Showing
7 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule LivebookWeb.UserController do | ||
use LivebookWeb, :controller | ||
|
||
def logout(conn, _params) do | ||
if get_session(conn, :user_id) do | ||
conn | ||
|> configure_session(renew: true) | ||
|> clear_session() | ||
|> render("logout.html") | ||
else | ||
redirect(conn, to: ~p"/") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
defmodule LivebookWeb.UserHTML do | ||
use LivebookWeb, :html | ||
|
||
embed_templates "user_html/*" | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule LivebookWeb.UserControllerTest do | ||
use LivebookWeb.ConnCase, async: true | ||
|
||
describe "GET /logout" do | ||
test "renders logout template when logged in", %{conn: conn} do | ||
conn = login_user(conn) | ||
|
||
conn = get(conn, ~p"/logout") | ||
|
||
assert html_response(conn, 200) =~ "You have been logged out" | ||
end | ||
|
||
test "redirects when already logged out", %{conn: conn} do | ||
conn = logout_user(conn) | ||
|
||
conn = get(conn, ~p"/logout") | ||
|
||
assert redirected_to(conn) == ~p"/" | ||
end | ||
|
||
defp login_user(conn) do | ||
Phoenix.ConnTest.init_test_session(conn, %{user_id: 1}) | ||
end | ||
|
||
defp logout_user(conn) do | ||
Phoenix.ConnTest.init_test_session(conn, %{}) | ||
end | ||
end | ||
end |