diff --git a/CHANGELOG.md b/CHANGELOG.md index 54daa3d22..1af1425a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this project will be documented in this file. +## [1.1.2] - 2020-10-14 + +### Fixed +- Do not error when activating an already activated account plausible/analytics#370 + ## [1.1.1] - 2020-10-14 ### Fixed diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 989845fc7..25c12eba9 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -65,11 +65,10 @@ defmodule PlausibleWeb.AuthController do PlausibleWeb.Email.welcome_email(user) |> Plausible.Mailer.send_email() - conn - |> put_session(:current_user_id, user.id) - |> put_resp_cookie("logged_in", "true", http_only: false) - |> redirect(to: "/password") - + user_activated_account(conn, user) + {:error, %Ecto.Changeset{errors: [email: {"has already been taken", _}]}} -> + user = Auth.find_user_by(email: email) + user_activated_account(conn, user) {:error, changeset} -> send_resp(conn, 400, inspect(changeset.errors)) end @@ -82,6 +81,13 @@ defmodule PlausibleWeb.AuthController do end end + defp user_activated_account(conn, user) do + conn + |> put_session(:current_user_id, user.id) + |> put_resp_cookie("logged_in", "true", http_only: false) + |> redirect(to: "/password") + end + def password_reset_request_form(conn, _) do render(conn, "password_reset_request_form.html", layout: {PlausibleWeb.LayoutView, "focus.html"} diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs index f7de93435..726b2b4f1 100644 --- a/test/plausible_web/controllers/auth_controller_test.exs +++ b/test/plausible_web/controllers/auth_controller_test.exs @@ -56,13 +56,13 @@ defmodule PlausibleWeb.AuthControllerTest do assert redirected_to(conn) == "/password" end - test "shows error when user with that email already exists", %{conn: conn} do + test "redirects existing user to create a password", %{conn: conn} do token = Plausible.Auth.Token.sign_activation("Jane Doe", "user@example.com") conn = get(conn, "/claim-activation?token=#{token}") conn = get(conn, "/claim-activation?token=#{token}") - assert conn.status == 400 + assert redirected_to(conn) == "/password" end end