diff --git a/lib/oli/accounts.ex b/lib/oli/accounts.ex index 820be3acb3e..5dfbd0bed2a 100644 --- a/lib/oli/accounts.ex +++ b/lib/oli/accounts.ex @@ -199,6 +199,17 @@ defmodule Oli.Accounts do """ def get_user_by(clauses), do: Repo.get_by(User, clauses) + @doc """ + Gets a single independent user by query parameter + ## Examples + iex> get_independent_user_by(email: "student1@example.com") + %User{independent_learner: true, ...} + iex> get_independent_user_by(email: "student2@example.com") + nil + """ + def get_independent_user_by(clauses), + do: Repo.get_by(User, Enum.into([independent_learner: true], clauses)) + @doc """ Gets a single user with platform roles and author preloaded Returns `nil` if the User does not exist. diff --git a/lib/oli_web/pow/messages.ex b/lib/oli_web/pow/messages.ex index 3c53a653e97..5f3fd1cb04f 100644 --- a/lib/oli_web/pow/messages.ex +++ b/lib/oli_web/pow/messages.ex @@ -58,17 +58,5 @@ defmodule OliWeb.Pow.Messages do end def pow_assent_login_with_provider(conn), - do: - interpolate("Continue with %{provider}", provider: Naming.humanize(conn.params["provider"])) - - defp interpolate(msg, opts) do - Enum.reduce(opts, msg, fn {key, value}, msg -> - token = "%{#{key}}" - - case String.contains?(msg, token) do - true -> String.replace(msg, token, to_string(value), global: false) - false -> msg - end - end) - end + do: "Continue with #{Naming.humanize(conn.params["provider"])}" end diff --git a/lib/oli_web/pow/user_context.ex b/lib/oli_web/pow/user_context.ex index daadbe00346..a47d3647d63 100644 --- a/lib/oli_web/pow/user_context.ex +++ b/lib/oli_web/pow/user_context.ex @@ -61,7 +61,7 @@ defmodule OliWeb.Pow.UserContext do """ @impl true def create(params) do - case Accounts.get_user_by(%{email: params["email"]}) do + case Accounts.get_independent_user_by(%{email: params["email"]}) do %User{email: email} = user -> if user.email_confirmed_at, do: @@ -70,8 +70,9 @@ defmodule OliWeb.Pow.UserContext do "Account already exists", "account_already_exists.html", %{ - url: Utils.ensure_absolute_url(Routes.pow_session_path(OliWeb.Endpoint, :new)), - forgot_password: + login_url: + Utils.ensure_absolute_url(Routes.pow_session_path(OliWeb.Endpoint, :new)), + forgot_password_url: Utils.ensure_absolute_url( Routes.pow_reset_password_reset_password_path(OliWeb.Endpoint, :new) ) diff --git a/lib/oli_web/pow/user_identities_context.ex b/lib/oli_web/pow/user_identities_context.ex index 9cdd4c18b9a..4fcf29da6d2 100644 --- a/lib/oli_web/pow/user_identities_context.ex +++ b/lib/oli_web/pow/user_identities_context.ex @@ -12,10 +12,9 @@ defmodule OliWeb.Pow.UserIdentities do %{"email" => email, "email_verified" => true} = user_params, user_id_params ) do - case Accounts.get_user_by(email: email) do + case Accounts.get_independent_user_by(email: email) do nil -> # user account with the given email doesnt exist, so create it - # user_params = Map.merge(user_params, %{"sub" => UUID.uuid4()}) pow_assent_create_user(user_identity_params, user_params, user_id_params) user -> diff --git a/lib/oli_web/templates/email/account_already_exists.html.eex b/lib/oli_web/templates/email/account_already_exists.html.eex index a558391a0e3..29fd6e16640 100644 --- a/lib/oli_web/templates/email/account_already_exists.html.eex +++ b/lib/oli_web/templates/email/account_already_exists.html.eex @@ -1,12 +1,23 @@ -
-

Are you trying to create a new account?

-

- Someone tried to create an account with this email but an account already exists. - If this was you, you can login <%= link "here", to: @url, target: "_blank" %> with your existing email and password. - If you forgot your password, you can reset it by clicking <%= link "Forgot Password?", to: @forgot_password, target: "_blank" %>. -

-

If this was not you, you can disregard this email.

-
- - - + + + + +
+ + + + +
+

Trying to create a new account?

+

+ We noticed there was an attempt to create a new account with this email but an account already exists. +

+

+ If this was you, <%= link "sign in to your existing account", to: @login_url, target: "_blank", style: "color: #2C67C4;" %>. + If you forgot your password, you can reset it <%= link "here", to: @forgot_password_url, target: "_blank", style: "color: #2C67C4;" %>. +

+

+ If this was not you, you can ignore this email. +

+
+