Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Do not error when activating an account that already exists (#370)

Uku Tahtdd44bc803d16
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54daa3d22b..1af1425a16 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 989845fc75..25c12eba91 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 f7de934359..726b2b4f12 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", "[email protected]")
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