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

* Do not error when activating an account that already exists

* Add changelog entry
pull/371/head
Uku Taht 6 years ago committed by GitHub
parent c84b5e1f76
commit dd44bc803d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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"}

@ -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

Loading…
Cancel
Save