-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert the login page to use controllers (#389)
* Fix bug in plug pipelines This prevented the MethodOverride plug from working, which allows us to make links that have a `DELETE` method for example. Also update the logout button to use delete. * Add ability to clear token * Add cancel button * Start AuthenticationController * [wip] first stage login checks phone validity * [wip] add second show action * Add cancelling * Fix most tests * Add tests; small refactor * Test and refactor for cancel * Remove dead code --------- Co-authored-by: teesloane <[email protected]>
- Loading branch information
Showing
10 changed files
with
202 additions
and
182 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,6 @@ | ||
defmodule BikeBrigadeWeb.AuthenticationHTML do | ||
use BikeBrigadeWeb, :html | ||
|
||
embed_templates "authentication_html/*" | ||
|
||
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
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 was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
test/bike_brigade_web/controllers/authentication_controller_test.exs
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,66 @@ | ||
defmodule BikeBrigadeWeb.AuthenticationControllerTest do | ||
use BikeBrigadeWeb.ConnCase | ||
alias BikeBrigade.{Accounts, AuthenticationMessenger} | ||
|
||
describe "login" do | ||
setup do | ||
rider = fixture(:rider) | ||
{:ok, user} = Accounts.create_user_for_rider(rider) | ||
|
||
%{user: user} | ||
end | ||
|
||
test "shows the login page", %{conn: conn} do | ||
conn = get(conn, ~p"/login") | ||
assert html_response(conn, 200) =~ "Sign into your Bike Brigade account" | ||
end | ||
|
||
test "errors when you send an invalid number", %{conn: conn} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: "5555555555555555"}}) | ||
assert html_response(conn, 200) =~ "phone number is not valid for Canada" | ||
end | ||
|
||
test "errors when you send a number that doesn't exist", %{conn: conn} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: "6475555555"}}) | ||
|
||
assert html_response(conn, 200) =~ | ||
"We can't find your number. Have you signed up for Bike Brigade?" | ||
end | ||
|
||
test "shows the token page when you give a valid number", %{conn: conn, user: user} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone}}) | ||
assert html_response(conn, 200) =~ "We sent an authentication code to your phone number" | ||
end | ||
|
||
test "errors when you send an invalid token", %{conn: conn, user: user} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone}}) | ||
|
||
token = Map.get(BikeBrigade.AuthenticationMessenger.get_state(), user.phone) | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone, token_attempt: "not a token"}}) | ||
|
||
assert redirected_to(conn) == ~p"/login?login[phone]=#{user.phone}" | ||
conn = get(conn, ~p"/login?login[phone]=#{user.phone}") | ||
assert html_response(conn, 200) =~ "Access code is invalid. Please try again." | ||
|
||
# Token is not regenerated after error | ||
assert Map.get(BikeBrigade.AuthenticationMessenger.get_state(), user.phone) == token | ||
end | ||
|
||
test "logs you in with valid token", %{conn: conn, user: user} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone}}) | ||
token = Map.get(BikeBrigade.AuthenticationMessenger.get_state(), user.phone) | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone, token_attempt: token}}) | ||
assert redirected_to(conn) == ~p"/" | ||
|
||
conn = get(conn, ~p"/home") | ||
assert html_response(conn, 200) =~ "Welcome!" | ||
end | ||
|
||
test "lets you cancel a login", %{conn: conn, user: user} do | ||
conn = post(conn, ~p"/login", %{login: %{phone: user.phone}}) | ||
conn = delete(conn, ~p"/login", %{phone: user.phone}) | ||
assert redirected_to(conn) == ~p"/login" | ||
assert Map.get(BikeBrigade.AuthenticationMessenger.get_state(), user.phone) == nil | ||
end | ||
end | ||
end |
Oops, something went wrong.