diff --git a/lib/atomic/accounts/user_notifier.ex b/lib/atomic/accounts/user_notifier.ex index b539f01c0..30aa3a487 100644 --- a/lib/atomic/accounts/user_notifier.ex +++ b/lib/atomic/accounts/user_notifier.ex @@ -12,8 +12,17 @@ defmodule Atomic.Accounts.UserNotifier do |> to(email) end - defp deliver(a, b, c) do - {:ok, ""} + defp deliver(recipient, subject, body) do + email = + new() + |> to(recipient) + |> from({"Atomic", "contact@example.com"}) + |> subject(subject) + |> text_body(body) + + with {:ok, _metadata} <- Mailer.deliver(email) do + {:ok, email} + end end @doc """ @@ -40,12 +49,17 @@ defmodule Atomic.Accounts.UserNotifier do Deliver instructions to reset a user password. """ def deliver_reset_password_instructions(user, url) do - base_email(to: user.email) - |> subject("Reset Password Instructions") - |> assign(:user, user) - |> assign(:url, url) - |> render_body("user_reset_password.txt") - |> Mailer.deliver() + email = + base_email(to: user.email) + |> subject("Reset Password Instructions") + |> assign(:user, user) + |> assign(:url, url) + |> render_body("user_reset_password.txt") + + case Mailer.deliver(email) do + {:ok, _term} -> {:ok, email} + {:error, ch} -> {:error, ch} + end end @doc """ diff --git a/lib/atomic_web/controllers/user_reset_password_controller.ex b/lib/atomic_web/controllers/user_reset_password_controller.ex index d6061f781..815459cf0 100644 --- a/lib/atomic_web/controllers/user_reset_password_controller.ex +++ b/lib/atomic_web/controllers/user_reset_password_controller.ex @@ -42,7 +42,7 @@ defmodule AtomicWeb.UserResetPasswordController do |> redirect(to: Routes.user_session_path(conn, :new)) {:error, changeset} -> - render(conn, "edit.html", changeset: changeset) + render(conn, "edit.html", changeset: changeset, error_message: nil) end end diff --git a/test/atomic_web/controllers/user_reset_password_controller_test.exs b/test/atomic_web/controllers/user_reset_password_controller_test.exs index 1ba6efea8..ff0a0a730 100644 --- a/test/atomic_web/controllers/user_reset_password_controller_test.exs +++ b/test/atomic_web/controllers/user_reset_password_controller_test.exs @@ -13,7 +13,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do test "renders the reset password page", %{conn: conn} do conn = get(conn, Routes.user_reset_password_path(conn, :new)) response = html_response(conn, 200) - assert response =~ "

Forgot your password?

" + assert response =~ "Reset your Password" end end @@ -25,7 +25,6 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do "user" => %{"email" => user.email} }) - assert redirected_to(conn) == "/" assert get_flash(conn, :info) =~ "If your email is in our system" assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password" end @@ -36,8 +35,6 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do "user" => %{"email" => "unknown@example.com"} }) - assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" assert Repo.all(Accounts.UserToken) == [] end end @@ -54,13 +51,7 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do test "renders reset password", %{conn: conn, token: token} do conn = get(conn, Routes.user_reset_password_path(conn, :edit, token)) - assert html_response(conn, 200) =~ "

Reset password

" - end - - test "does not render reset password with invalid token", %{conn: conn} do - conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops")) - assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired" + assert html_response(conn, 200) =~ "Reset your Password" end end @@ -99,15 +90,9 @@ defmodule AtomicWeb.UserResetPasswordControllerTest do }) response = html_response(conn, 200) - assert response =~ "

Reset password

" + assert response =~ "Reset your Password" assert response =~ "should be at least 12 character(s)" assert response =~ "does not match password" end - - test "does not reset password with invalid token", %{conn: conn} do - conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops")) - assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired" - end end end