From f62ba74aac2c43a639e4b34b957512892df5e4b3 Mon Sep 17 00:00:00 2001 From: Andrew Hebert <108428778+ah-s76@users.noreply.github.com> Date: Wed, 15 May 2024 15:05:59 -0400 Subject: [PATCH] add button for redirect to store home (#150) "continue shopping" button added for configurable return to home page. --- config/dev.exs | 5 ++-- config/releases.exs | 5 ++-- config/test.exs | 5 ++-- lib/recognizer/bigcommerce.ex | 10 ++++---- .../accounts/user_settings_controller.ex | 24 +++++++++++++------ .../accounts/user_settings/edit.html.eex | 21 ++++------------ .../user_settings_controller_test.exs | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index dd44b01..98a6ea6 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -59,8 +59,9 @@ config :recognizer, Recognizer.BigCommerce, client_secret: "bc_secret", access_token: "bc_access_token", store_hash: "bc_store_hash", - login_uri: "http://localhost/login/", - logout_uri: "http://localhost/logout", + store_home_uri: "http://localhost", + login_path: "/login", + logout_path: "/logout", http_client: HTTPoison, enabled?: false diff --git a/config/releases.exs b/config/releases.exs index 6461d71..1a26856 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -74,8 +74,9 @@ config :recognizer, Recognizer.BigCommerce, client_secret: recognizer_config["BIGCOMMERCE_CLIENT_SECRET"], access_token: recognizer_config["BIGCOMMERCE_ACCESS_TOKEN"], store_hash: recognizer_config["BIGCOMMERCE_STORE_HASH"], - login_uri: recognizer_config["BIGCOMMERCE_LOGIN_URI"], - logout_uri: recognizer_config["BIGCOMMERCE_LOGOUT_URI"], + store_home_uri: recognizer_config["BIGCOMMERCE_HOME_URI"], + login_path: recognizer_config["BIGCOMMERCE_LOGIN_PATH"], + logout_path: recognizer_config["BIGCOMMERCE_LOGOUT_PATH"], http_client: HTTPoison, enabled?: false diff --git a/config/test.exs b/config/test.exs index 38513f3..d359286 100644 --- a/config/test.exs +++ b/config/test.exs @@ -37,8 +37,9 @@ config :recognizer, Recognizer.BigCommerce, client_secret: "bc_secret", access_token: "bc_access_token", store_hash: "bc_store_hash", - login_uri: "http://localhost/login/", - logout_uri: "http://localhost/logout", + store_home_uri: "http://localhost", + login_path: "/login/", + logout_path: "/logout", http_client: HTTPoisonMock, enabled?: true diff --git a/lib/recognizer/bigcommerce.ex b/lib/recognizer/bigcommerce.ex index 259659a..e8a6ff8 100644 --- a/lib/recognizer/bigcommerce.ex +++ b/lib/recognizer/bigcommerce.ex @@ -37,13 +37,11 @@ defmodule Recognizer.BigCommerce do end end - def login_redirect_uri(user) do - config(:login_uri) <> generate_login_jwt(user) - end + def home_redirect_uri(), do: config(:store_home_uri) - def logout_redirect_uri() do - config(:logout_uri) - end + def login_redirect_uri(user), do: home_redirect_uri() <> config(:login_path) <> generate_login_jwt(user) + + def logout_redirect_uri(), do: home_redirect_uri() <> config(:logout_path) defp generate_login_jwt(user) do {:ok, token, _claims} = diff --git a/lib/recognizer_web/controllers/accounts/user_settings_controller.ex b/lib/recognizer_web/controllers/accounts/user_settings_controller.ex index 90ff748..ad4d1ba 100644 --- a/lib/recognizer_web/controllers/accounts/user_settings_controller.ex +++ b/lib/recognizer_web/controllers/accounts/user_settings_controller.ex @@ -3,11 +3,13 @@ defmodule RecognizerWeb.Accounts.UserSettingsController do alias Recognizer.Accounts alias Recognizer.Accounts.Role + alias Recognizer.BigCommerce alias RecognizerWeb.Authentication @one_minute 60_000 plug :assign_email_and_password_changesets + plug :assign_common plug Hammer.Plug, [ @@ -25,13 +27,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsController do if Application.get_env(:recognizer, :redirect_url) && !get_session(conn, :bc) do redirect(conn, external: Application.get_env(:recognizer, :redirect_url)) else - # disable phone/text 2fa methods for admins - is_admin = - conn - |> Authentication.fetch_current_user() - |> Role.admin?() - - render(conn, "edit.html", allow_phone_methods: !is_admin) + render(conn, "edit.html") end end @@ -196,4 +192,18 @@ defmodule RecognizerWeb.Accounts.UserSettingsController do |> assign(:password_changeset, Accounts.change_user_password(user)) |> assign(:two_factor_changeset, Accounts.change_user_two_factor(user)) end + + defp assign_common(conn, _opts) do + home_uri = BigCommerce.home_redirect_uri() + + # disable phone/text 2fa methods for admins + is_admin = + conn + |> Authentication.fetch_current_user() + |> Role.admin?() + + conn + |> assign(:redirect_home, home_uri) + |> assign(:allow_phone_methods, !is_admin) + end end diff --git a/lib/recognizer_web/templates/accounts/user_settings/edit.html.eex b/lib/recognizer_web/templates/accounts/user_settings/edit.html.eex index a07ddf4..240c4b0 100644 --- a/lib/recognizer_web/templates/accounts/user_settings/edit.html.eex +++ b/lib/recognizer_web/templates/accounts/user_settings/edit.html.eex @@ -1,15 +1,6 @@ -
- This will log you out of this website, but not the system76.com - website, or any other third party websites you have logged in on. -
- -