diff --git a/apps/alert_processor/lib/model/user.ex b/apps/alert_processor/lib/model/user.ex
index 5e4f69976..3a1ed1d89 100644
--- a/apps/alert_processor/lib/model/user.ex
+++ b/apps/alert_processor/lib/model/user.ex
@@ -242,15 +242,6 @@ defmodule AlertProcessor.Model.User do
end
end
- @doc """
- Builds a changeset to verify login
- """
- def login_changeset(struct, params \\ %{}) do
- struct
- |> cast(params, [:email, :password])
- |> validate_required([:email, :password])
- end
-
def opt_in_phone_number(%__MODULE__{phone_number: nil}), do: {:ok, nil}
def opt_in_phone_number(%__MODULE__{phone_number: phone_number}) do
@@ -259,39 +250,6 @@ defmodule AlertProcessor.Model.User do
|> AwsClient.request()
end
- @doc """
- Checks if user's login credentials are valid
- """
- def authenticate(%{"email" => email, "password" => password} = params) do
- changeset = login_changeset(%__MODULE__{}, params)
-
- case changeset.errors do
- [] ->
- user = Repo.get_by(__MODULE__, email: String.downcase(email))
-
- cond do
- user && user.encrypted_password == "" ->
- {:error, :disabled}
-
- check_password(user, password) ->
- {:ok, user}
-
- true ->
- {:error, changeset}
- end
-
- _ ->
- {:error, changeset}
- end
- end
-
- def check_password(user, password) do
- case user do
- nil -> Bcrypt.no_user_verify()
- _ -> Bcrypt.verify_pass(password, user.encrypted_password)
- end
- end
-
@doc "Records an email rejection status for a user and disables notifications for them."
def set_email_rejection(user, status) when not is_nil(status),
do: update_email_rejection(user, "none", status, "email-rejection")
diff --git a/apps/alert_processor/test/alert_processor/model/user_test.exs b/apps/alert_processor/test/alert_processor/model/user_test.exs
index f9558649c..1cda79cc5 100644
--- a/apps/alert_processor/test/alert_processor/model/user_test.exs
+++ b/apps/alert_processor/test/alert_processor/model/user_test.exs
@@ -13,9 +13,6 @@ defmodule AlertProcessor.Model.UserTest do
"communication_mode" => "email"
}
@invalid_attrs %{}
- @password "password1"
- @encrypted_password Bcrypt.hash_pwd_salt(@password)
- @disabled_password ""
describe "user changeset" do
test "changeset with valid attributes" do
@@ -194,58 +191,6 @@ defmodule AlertProcessor.Model.UserTest do
end
end
- describe "authenticate/1" do
- test "authenticates if email and password valid" do
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- assert {:ok, _} = User.authenticate(%{"email" => "test@email.com", "password" => @password})
- end
-
- test "does not authenticate if invalid password for existing user" do
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- assert {:error, _} =
- User.authenticate(%{
- "email" => "test@email.com",
- "password" => "different_password"
- })
- end
-
- test "does not authenticate if user doesn't exist" do
- assert {:error, _} =
- User.authenticate(%{"email" => "nope@invalid.com", "password" => @password})
- end
-
- test "does not authenticate if user's account is disabled" do
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @disabled_password
- })
-
- assert {:error, :disabled} =
- User.authenticate(%{"email" => "test@email.com", "password" => @password})
- end
-
- test "email is not case sensitive" do
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- assert {:ok, _} = User.authenticate(%{"email" => "TEST@EMAIL.COM", "password" => @password})
- end
- end
-
describe "set_email_rejection/2" do
test "sets a user's email rejection status and disables notifications" do
user = insert(:user, communication_mode: "email", email_rejection_status: nil)
diff --git a/apps/concierge_site/lib/controllers/account_controller.ex b/apps/concierge_site/lib/controllers/account_controller.ex
index c5c69ed98..fbcba61a0 100644
--- a/apps/concierge_site/lib/controllers/account_controller.ex
+++ b/apps/concierge_site/lib/controllers/account_controller.ex
@@ -4,55 +4,22 @@ defmodule ConciergeSite.AccountController do
alias AlertProcessor.Model.User
alias AlertProcessor.Repo
alias ConciergeSite.ConfirmationMessage
- alias ConciergeSite.SessionHelper
alias ConciergeSite.Mailchimp
require Logger
def new(conn, _params) do
- if SessionHelper.keycloak_auth?() do
- redirect(conn, to: "/auth/keycloak/register")
- else
- render(conn, "new.html", account_changeset: new_user_changeset())
- end
+ redirect(conn, to: "/auth/keycloak/register")
end
def edit(%{assigns: %{current_user: user}} = conn, _params) do
conn
|> put_flash(:warning, communication_mode_flash(user))
- |> render(edit_template(), changeset: User.changeset(user), user_id: user.id)
+ |> render("edit.html", changeset: User.changeset(user), user_id: user.id)
end
def edit_password(conn, _params) do
- if SessionHelper.keycloak_auth?() do
- redirect(conn, external: ConciergeSite.AccountView.edit_password_url(conn))
- else
- render(conn, "edit_password.html")
- end
- end
-
- def create(conn, %{"user" => params, "g-recaptcha-response" => recaptcha_response}) do
- with {:ok, _resp} <- Recaptcha.verify(recaptcha_response),
- {:ok, user} <- User.create_account(params) do
- SessionHelper.sign_in(conn, user)
- else
- {:error, errors} when is_list(errors) ->
- Logger.warn("AccountController event=recaptcha_error errors=#{Enum.join(errors, ",")}")
-
- conn
- |> put_flash(:error, "reCAPTCHA validation error. Please try again.")
- |> render("new.html", account_changeset: new_user_changeset(params))
-
- {:error, %Ecto.Changeset{} = changeset} ->
- render(conn, "new.html", account_changeset: changeset, errors: errors(changeset))
- end
- end
-
- def create(conn, _params) do
- conn
- |> put_flash(:error, "Required params error. \
- Please ensure your web browser is up-to-date and you have JavaScript enabled.")
- |> render("new.html", account_changeset: new_user_changeset())
+ redirect(conn, external: ConciergeSite.AccountView.edit_password_url(conn))
end
def update(%{assigns: %{current_user: user}} = conn, %{"user" => params}) do
@@ -74,7 +41,7 @@ defmodule ConciergeSite.AccountController do
{:error, changeset} ->
render(
conn,
- edit_template(),
+ "edit.html",
changeset: changeset,
user_id: user.id,
errors: errors(changeset)
@@ -82,26 +49,6 @@ defmodule ConciergeSite.AccountController do
end
end
- def update_password(%{assigns: %{current_user: user}} = conn, %{"user" => params}) do
- if User.check_password(user, params["current_password"]) do
- case User.update_password(user, %{"password" => params["password"]}, user) do
- {:ok, _} ->
- conn
- |> put_flash(:info, "Your password has been updated.")
- |> redirect(to: trip_path(conn, :index))
-
- {:error, _} ->
- conn
- |> put_flash(:error, "New password format is incorrect. Please try again.")
- |> render("edit_password.html")
- end
- else
- conn
- |> put_flash(:error, "Current password is incorrect. Please try again.")
- |> render("edit_password.html")
- end
- end
-
def delete(%{assigns: %{current_user: user}} = conn, _params) do
Mailchimp.delete_member(user)
Repo.delete!(user)
@@ -144,9 +91,6 @@ defmodule ConciergeSite.AccountController do
end)
end
- defp new_user_changeset(params \\ %{"sms_toggle" => false}),
- do: User.create_account_changeset(%User{}, params)
-
defp communication_mode_flash(%User{sms_opted_out_at: sms_opted_out_at} = user)
when not is_nil(sms_opted_out_at) do
communication_mode_flash_for_sms_opt_out(user, User.inside_opt_out_freeze_window?(user))
@@ -238,7 +182,4 @@ defmodule ConciergeSite.AccountController do
def mailchimp_update(conn, _params) do
json(conn, %{status: "ok", message: "invalid request"})
end
-
- defp edit_template,
- do: if(SessionHelper.keycloak_auth?(), do: "edit_keycloak.html", else: "edit.html")
end
diff --git a/apps/concierge_site/lib/controllers/session_controller.ex b/apps/concierge_site/lib/controllers/session_controller.ex
index 524fbb86f..f1bc620a8 100644
--- a/apps/concierge_site/lib/controllers/session_controller.ex
+++ b/apps/concierge_site/lib/controllers/session_controller.ex
@@ -1,28 +1,10 @@
defmodule ConciergeSite.SessionController do
use ConciergeSite.Web, :controller
- alias AlertProcessor.Model.User
alias ConciergeSite.SessionHelper
plug(:scrub_params, "user" when action in [:create])
def new(conn, _params) do
- if SessionHelper.keycloak_auth?() do
- redirect(conn, to: "/auth/keycloak")
- else
- changeset = User.login_changeset(%User{})
- render(conn, "new.html", login_changeset: changeset)
- end
- end
-
- def create(conn, %{"user" => login_params}) do
- case User.authenticate(login_params) do
- {:ok, user} ->
- SessionHelper.sign_in(conn, user)
-
- {:error, changeset} ->
- conn
- |> put_flash(:error, "Sorry, your login information was incorrect. Please try again.")
- |> render("new.html", login_changeset: changeset)
- end
+ redirect(conn, to: "/auth/keycloak")
end
def delete(conn, _params) do
diff --git a/apps/concierge_site/lib/helpers/session_helper.ex b/apps/concierge_site/lib/helpers/session_helper.ex
index 7fb79a32f..a30090905 100644
--- a/apps/concierge_site/lib/helpers/session_helper.ex
+++ b/apps/concierge_site/lib/helpers/session_helper.ex
@@ -19,19 +19,12 @@ defmodule ConciergeSite.SessionHelper do
@spec sign_out(Conn.t()) :: Conn.t()
def sign_out(conn) do
- redirect_to =
- if keycloak_auth?() do
- id_token = conn |> Guardian.Plug.current_claims() |> Map.get("id_token")
-
- [
- external:
- URI.encode(
- "#{System.get_env("KEYCLOAK_LOGOUT_URI")}?post_logout_redirect_uri=#{page_url(conn, :landing)}&id_token_hint=#{id_token}"
- )
- ]
- else
- [to: page_path(conn, :landing)]
- end
+ redirect_to = [
+ external:
+ URI.encode(
+ "#{System.get_env("KEYCLOAK_LOGOUT_URI")}?post_logout_redirect_uri=#{page_url(conn, :landing)}&id_token_hint=#{id_token(conn)}"
+ )
+ ]
conn
|> put_flash(:info, "You have been signed out.")
@@ -40,12 +33,6 @@ defmodule ConciergeSite.SessionHelper do
|> redirect(redirect_to)
end
- @spec keycloak_auth? :: boolean()
- def keycloak_auth? do
- Application.get_env(:concierge_site, ConciergeSite.Endpoint)[:authentication_source] ==
- "keycloak"
- end
-
defp sign_in_redirect_path(user) do
if Trip.get_trips_by_user(user.id) == [] do
account_path(@endpoint, :options_new)
@@ -53,4 +40,11 @@ defmodule ConciergeSite.SessionHelper do
trip_path(@endpoint, :index)
end
end
+
+ @spec id_token(Conn.t()) :: String.t()
+ defp id_token(conn) do
+ conn
+ |> Guardian.Plug.current_claims()
+ |> Map.get("id_token")
+ end
end
diff --git a/apps/concierge_site/lib/router.ex b/apps/concierge_site/lib/router.ex
index aaaa4d6c1..46b9248b9 100644
--- a/apps/concierge_site/lib/router.ex
+++ b/apps/concierge_site/lib/router.ex
@@ -64,7 +64,7 @@ defmodule ConciergeSite.Router do
post("/api/feedback", FeedbackController, :new)
get("/digest/feedback", DigestFeedbackController, :feedback)
post("/api/digest/feedback", DigestFeedbackController, :new)
- resources("/login", SessionController, only: [:new, :create], singleton: true)
+ resources("/login", SessionController, only: [:new], singleton: true)
resources("/account", AccountController, only: [:new, :create])
resources("/password_resets", PasswordResetController, only: [:new, :create, :edit, :update])
end
@@ -80,7 +80,6 @@ defmodule ConciergeSite.Router do
post("/account/edit", AccountController, :update)
delete("/account/delete", AccountController, :delete)
get("/password/edit", AccountController, :edit_password)
- post("/password/edit", AccountController, :update_password)
resources("/trips", TripController, only: [:index, :edit, :update, :delete]) do
patch("/pause", TripController, :pause, as: :pause)
diff --git a/apps/concierge_site/lib/templates/account/edit.html.eex b/apps/concierge_site/lib/templates/account/edit.html.eex
index 420a0ac83..24dd13c79 100644
--- a/apps/concierge_site/lib/templates/account/edit.html.eex
+++ b/apps/concierge_site/lib/templates/account/edit.html.eex
@@ -32,29 +32,32 @@
+ <%= if phone_number?(@current_user) do %>
+
+
+ SMS messages will be sent to <%= @current_user |> phone_number() |> format_phone_number() %>.
+ <%= link to: update_profile_url(@conn) do %>Change phone number<% end %>
+
-
diff --git a/apps/concierge_site/lib/templates/account/edit_keycloak.html.eex b/apps/concierge_site/lib/templates/account/edit_keycloak.html.eex
deleted file mode 100644
index 24dd13c79..000000000
--- a/apps/concierge_site/lib/templates/account/edit_keycloak.html.eex
+++ /dev/null
@@ -1,96 +0,0 @@
-Settings
-<%= flash_error(@conn) %>
-<%= flash_warning(@conn) %>
-
-<% communication_mode = fetch_field!(@changeset, :communication_mode) %>
-
-
-
-
- <%= form_for @changeset, account_path(@conn, :update), [as: :user, method: :post], fn form -> %>
-
-
-
-
-
- <%= checkbox form, :digest_opt_in, class: "form-check-input" %>
- <%= label form, :digest_opt_in, "Yes, send me a weekly email about planned service disruptions across the MBTA.", class: "form__label--radio" %>
- Even if you receive text alerts, this will be sent to the email address you signed up with.
-
-
-
- <%= submit "Update account settings", class: "btn btn-primary btn-login btn-block" %>
-
- <% end %>
-
-
-
Your MBTA Account
-
- -
- <%= link to: update_profile_url(@conn) do %>Update your email address<% end %>
-
- (currently <%= email(@current_user) %>)
-
-
- -
- <%= link to: account_path(@conn, :edit_password) do %>Choose a new password<% end %>
-
- -
- Delete my account
-
-
-
-
-
-
-
-
-<%= render ConciergeSite.LayoutView, "_delete_modal.html", assigns %>
diff --git a/apps/concierge_site/lib/templates/account/edit_password.html.eex b/apps/concierge_site/lib/templates/account/edit_password.html.eex
deleted file mode 100644
index 1aedbc30d..000000000
--- a/apps/concierge_site/lib/templates/account/edit_password.html.eex
+++ /dev/null
@@ -1,28 +0,0 @@
-Update password
-<%= flash_error(@conn) %>
-
-
-
-
- <%= form_for @conn, account_path(@conn, :update_password), [as: :user, method: :post], fn f -> %>
-
- <%= label f, :current_password, "Current Password", class: "form__label" %>
- <%= error_tag f, :current_password %>
- <%= password_input f, :current_password, placeholder: "Enter your current password", class: "form-control", required: true %>
-
-
-
-
-
- <%= submit "Update password", class: "btn btn-primary btn-login btn-block" %>
-
-
- <% end %>
-
-
-
diff --git a/apps/concierge_site/lib/templates/account/new.html.eex b/apps/concierge_site/lib/templates/account/new.html.eex
deleted file mode 100644
index 136b7deea..000000000
--- a/apps/concierge_site/lib/templates/account/new.html.eex
+++ /dev/null
@@ -1,47 +0,0 @@
-Sign up
-<%= flash_error(@conn) %>
-<%= flash_info(@conn) %>
-
-Already have an account?
- <%= link(to: session_path(@conn, :new)) do %>
- Log in
-
- <% end %>
-
-
-
-
-
- <%= form_for @account_changeset, account_path(@conn, :create), fn f -> %>
-
-
- <%= label f, :email, "Enter your email", class: "form__label" %>
- <%= text_input f, :email, placeholder: "your@email.com", class: "form-control" %>
- <%= error_tag f, :email, "Email" %>
-
-
-
-
-
- <%= raw Recaptcha.Template.display(onload: "enableSignUpButton") %>
-
-
- <%= submit "Create my account",
- id: "sign-up-button",
- class: "btn btn-primary btn-login btn-block",
- disabled: true %>
-
-
- <% end %>
-
-
-
diff --git a/apps/concierge_site/lib/templates/account/options_new.html.eex b/apps/concierge_site/lib/templates/account/options_new.html.eex
index 332a51624..e7111cd24 100644
--- a/apps/concierge_site/lib/templates/account/options_new.html.eex
+++ b/apps/concierge_site/lib/templates/account/options_new.html.eex
@@ -31,22 +31,16 @@
" data-phone="input">
- <%= if keycloak_auth?() do %>
- <%= if phone_number?(@current_user) do %>
- <%= label form, :phone_number, "My phone number is:", class: "form__label d-block" %>
-
<%= @current_user |> phone_number() |> format_phone_number() %>
- <% else %>
-
Please enter your number in order to recieve text messages.
-
<%= link to: update_profile_url(@conn) do %>Add phone number<% end %>
- <%= error_tag form, :phone_number %>
- <% end %>
+ <%= if phone_number?(@current_user) do %>
+ <%= label form, :phone_number, "My phone number is:", class: "form__label d-block" %>
+
<%= @current_user |> phone_number() |> format_phone_number() %>
<% else %>
- <%= label form, :phone_number, "What’s your mobile phone number?", class: "form__label d-block" %>
- <%= telephone_input form, :phone_number, autocomplete: "off", placeholder: "###-###-####", class: "form-control d-inline-block form__phone--input", data: [toggle: "input"] %>
+
Please enter your number in order to recieve text messages.
+
<%= link to: update_profile_url(@conn) do %>Add phone number<% end %>
<%= error_tag form, :phone_number %>
<% end %>
- <%= if !keycloak_auth?() or phone_number(@current_user) do %>
+ <%= if phone_number(@current_user) do %>
<%= checkbox form, :accept_tnc, class: "form-check-input" %>
<%= label form, :accept_tnc, class: "form__label-radio" do %>
@@ -59,8 +53,7 @@
Text "STOP" to 58541 to unsubscribe
<%= error_tag form, :accept_tnc %>
-
-
+
<% end %>
diff --git a/apps/concierge_site/lib/templates/page/landing.html.eex b/apps/concierge_site/lib/templates/page/landing.html.eex
index ffff1adec..6990b921a 100644
--- a/apps/concierge_site/lib/templates/page/landing.html.eex
+++ b/apps/concierge_site/lib/templates/page/landing.html.eex
@@ -11,11 +11,7 @@
- <%= if keycloak_auth?() do %>
- <%= link "Create your MBTA account", to: account_path(@conn, :new), class: "btn btn-primary btn-block" %>
- <% else %>
- <%= link "Create an account", to: account_path(@conn, :new), class: "btn btn-primary btn-block" %>
- <% end %>
+ <%= link "Create your MBTA account", to: account_path(@conn, :new), class: "btn btn-primary btn-block" %>
<%= link "Sign in", to: session_path(@conn, :new), class: "btn btn-outline-primary btn-block" %>
diff --git a/apps/concierge_site/lib/templates/session/new.html.eex b/apps/concierge_site/lib/templates/session/new.html.eex
deleted file mode 100644
index f0302e2b7..000000000
--- a/apps/concierge_site/lib/templates/session/new.html.eex
+++ /dev/null
@@ -1,35 +0,0 @@
-
Sign in
-<%= flash_error(@conn) %>
-<%= flash_info(@conn) %>
-
-
Don't have an account?
- <%= link(to: account_path(@conn, :new)) do %>
- Sign up
-
- <% end %>
-
-
-
-
-
- <%= form_for @login_changeset, session_path(@conn, :create), fn f -> %>
-
- <%= label f, :email, "Email login", class: "form__label" %>
- <%= email_input f, :email, placeholder: "your@email.com", class: "form-control" %>
- <%= error_tag f, :email %>
-
-
-
- <%= submit "Go to my account", class: "btn btn-primary btn btn-block" %>
-
- <% end %>
-
-
-
diff --git a/apps/concierge_site/lib/views/account_view.ex b/apps/concierge_site/lib/views/account_view.ex
index 1cf6ad043..348a8e23b 100644
--- a/apps/concierge_site/lib/views/account_view.ex
+++ b/apps/concierge_site/lib/views/account_view.ex
@@ -2,11 +2,9 @@ defmodule ConciergeSite.AccountView do
use ConciergeSite.Web, :view
alias AlertProcessor.Model.User
- alias ConciergeSite.SessionHelper
alias Ecto.Changeset
alias Plug.Conn
- defdelegate keycloak_auth?, to: SessionHelper
defdelegate email(user), to: User
defdelegate phone_number(user), to: User
diff --git a/apps/concierge_site/lib/views/page_view.ex b/apps/concierge_site/lib/views/page_view.ex
index e3222e364..d3ce9cc0c 100644
--- a/apps/concierge_site/lib/views/page_view.ex
+++ b/apps/concierge_site/lib/views/page_view.ex
@@ -1,7 +1,3 @@
defmodule ConciergeSite.PageView do
use ConciergeSite.Web, :view
-
- alias ConciergeSite.SessionHelper
-
- defdelegate keycloak_auth?, to: SessionHelper
end
diff --git a/apps/concierge_site/test/web/controllers/account_controller_test.exs b/apps/concierge_site/test/web/controllers/account_controller_test.exs
index 4c9219a21..d5118839e 100644
--- a/apps/concierge_site/test/web/controllers/account_controller_test.exs
+++ b/apps/concierge_site/test/web/controllers/account_controller_test.exs
@@ -8,13 +8,7 @@ defmodule ConciergeSite.AccountControllerTest do
alias AlertProcessor.Repo
describe "new/4" do
- test "using local auth, displays the Sign up page", %{conn: conn} do
- reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "local")
- conn = get(conn, account_path(conn, :new))
- assert html_response(conn, 200) =~ "Sign up"
- end
-
- test "using keycloak auth, redirects to the keycloak register route", %{conn: conn} do
+ test "redirects to the keycloak register route", %{conn: conn} do
reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "keycloak")
conn = get(conn, account_path(conn, :new))
assert redirected_to(conn) == "/auth/keycloak/register"
@@ -333,19 +327,6 @@ defmodule ConciergeSite.AccountControllerTest do
end
describe "update password" do
- test "GET /password/edit - for local auth", %{conn: conn} do
- reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "local")
-
- user = insert(:user)
-
- conn =
- user
- |> guardian_login(conn)
- |> get(account_path(conn, :edit_password))
-
- assert html_response(conn, 200) =~ "Update password"
- end
-
test "GET /password/edit - for Keycloak auth", %{conn: conn} do
reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "keycloak")
@@ -359,45 +340,6 @@ defmodule ConciergeSite.AccountControllerTest do
assert redirected_to(conn, 302) =~
~r/\/auth\/realms\/MBTA\/protocol\/openid-connect\/auth?.*kc_action=UPDATE_PASSWORD/
end
-
- test "POST /password/edit", %{conn: conn} do
- user = insert(:user, encrypted_password: Bcrypt.hash_pwd_salt("Password1!"))
-
- user_params = %{current_password: "Password1!", password: "Password2!"}
-
- conn =
- user
- |> guardian_login(conn)
- |> post(account_path(conn, :update_password), %{user: user_params})
-
- assert html_response(conn, 302) =~ "/trips"
- end
-
- test "POST /password/edit no match error", %{conn: conn} do
- user = insert(:user, encrypted_password: Bcrypt.hash_pwd_salt("Password1!"))
-
- user_params = %{current_password: "Password3!", password: "Password2!"}
-
- conn =
- user
- |> guardian_login(conn)
- |> post(account_path(conn, :update_password), %{user: user_params})
-
- assert html_response(conn, 200) =~ "Current password is incorrect"
- end
-
- test "POST /password/edit validation error", %{conn: conn} do
- user = insert(:user, encrypted_password: Bcrypt.hash_pwd_salt("Password1!"))
-
- user_params = %{current_password: "Password1!", password: "Password"}
-
- conn =
- user
- |> guardian_login(conn)
- |> post(account_path(conn, :update_password), %{user: user_params})
-
- assert html_response(conn, 200) =~ "New password format is incorrect"
- end
end
describe "account delete" do
diff --git a/apps/concierge_site/test/web/controllers/session_controller_test.exs b/apps/concierge_site/test/web/controllers/session_controller_test.exs
index 7f66cdac6..116750d8f 100644
--- a/apps/concierge_site/test/web/controllers/session_controller_test.exs
+++ b/apps/concierge_site/test/web/controllers/session_controller_test.exs
@@ -3,22 +3,10 @@ defmodule ConciergeSite.SessionControllerTest do
use ConciergeSite.ConnCase
import AlertProcessor.Factory
import Test.Support.Helpers
- alias AlertProcessor.{Model.User, Model.Trip, Repo}
alias Hammer
- @password "password1"
- @encrypted_password Bcrypt.hash_pwd_salt(@password)
-
describe "GET /login/new" do
- test "for local auth", %{conn: conn} do
- reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "local")
-
- conn = get(conn, session_path(conn, :new))
-
- assert html_response(conn, 200) =~ "Sign in"
- end
-
- test "for Keycloak auth", %{conn: conn} do
+ test "redirects to Keycloak login page", %{conn: conn} do
reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "keycloak")
conn = get(conn, session_path(conn, :new))
@@ -27,67 +15,6 @@ defmodule ConciergeSite.SessionControllerTest do
end
end
- test "POST /login", %{conn: conn} do
- user =
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- params = %{"user" => %{"email" => user.email, "password" => @password}}
- conn = post(conn, session_path(conn, :create), params)
- assert html_response(conn, 302) =~ "/account/options"
- end
-
- test "POST /login with trips", %{conn: conn} do
- user =
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- Repo.insert!(%Trip{
- user_id: user.id,
- relevant_days: [:monday],
- start_time: ~T[12:00:00],
- end_time: ~T[18:00:00],
- facility_types: [:elevator]
- })
-
- params = %{"user" => %{"email" => user.email, "password" => @password}}
- conn = post(conn, session_path(conn, :create), params)
- assert html_response(conn, 302) =~ "
"
- end
-
- test "POST /login rejected", %{conn: conn} do
- user =
- Repo.insert!(%User{
- email: "test@email.com",
- role: "user",
- encrypted_password: @encrypted_password
- })
-
- params = %{"user" => %{"email" => user.email, "password" => "11111111111"}}
- conn = post(conn, session_path(conn, :create), params)
- assert html_response(conn, 200) =~ "information was incorrect"
- end
-
- test "POST /login rate-limited", %{conn: conn} do
- on_exit(fn -> true = :ets.delete_all_objects(:hammer_ets_buckets) end)
- params = %{"user" => %{"email" => "test2@email.com", "password" => "11111111111"}}
-
- [first_attempt, _, _, _, next_to_last_attempt, last_attempt] =
- for _ <- 1..6 do
- conn |> assign(:rate_limit?, true) |> post(session_path(conn, :create), params)
- end
-
- assert first_attempt.status == 200
- assert next_to_last_attempt.status == 200
- assert last_attempt.status == 429
- end
-
test "DELETE /login", %{conn: conn} do
reassign_env(:concierge_site, ConciergeSite.Endpoint, authentication_source: "local")