UX: Wizard resends activation email when user exists

This commit is contained in:
Gerhard Schlager 2018-08-21 19:11:18 +02:00
parent d1607a387a
commit 17dc8f2490
2 changed files with 46 additions and 15 deletions

View File

@ -15,7 +15,11 @@ class FinishInstallationController < ApplicationController
email = params[:email].strip
raise Discourse::InvalidParameters.new unless @allowed_emails.include?(email)
return redirect_confirm(email) if UserEmail.where("lower(email) = ?", email).exists?
if existing_user = User.find_by_email(email)
@user = existing_user
send_signup_email
return redirect_confirm(email)
end
@user.email = email
@user.username = params[:username]
@ -23,8 +27,7 @@ class FinishInstallationController < ApplicationController
@user.password_required!
if @user.save
@email_token = @user.email_tokens.unconfirmed.active.first
Jobs.enqueue(:critical_user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
send_signup_email
return redirect_confirm(@user.email)
end
@ -38,16 +41,22 @@ class FinishInstallationController < ApplicationController
def resend_email
@email = session[:registered_email]
@user = User.find_by_email(@email)
if @user.present?
@email_token = @user.email_tokens.unconfirmed.active.first
if @email_token.present?
Jobs.enqueue(:critical_user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
end
end
send_signup_email if @user.present?
end
protected
def send_signup_email
email_token = @user.email_tokens.unconfirmed.active.first
if email_token.present?
Jobs.enqueue(:critical_user_email,
type: :signup,
user_id: @user.id,
email_token: email_token.token)
end
end
def redirect_confirm(email)
session[:registered_email] = email
redirect_to(finish_installation_confirm_email_path)

View File

@ -68,18 +68,40 @@ describe FinishInstallationController do
expect(response).not_to be_redirect
end
it "registers the admin when the email is in the list" do
expect do
post "/finish-installation/register.json", params: {
context "working params" do
let(:params) do
{
email: 'robin@example.com',
username: 'eviltrout',
password: 'disismypasswordokay'
}
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
end
expect(response).to be_redirect
expect(User.where(username: 'eviltrout').exists?).to eq(true)
it "registers the admin when the email is in the list" do
expect do
post "/finish-installation/register.json", params: params
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
expect(response).to be_redirect
expect(User.where(username: 'eviltrout').exists?).to eq(true)
end
it "automatically resends the signup email when the user already exists" do
expect do
post "/finish-installation/register.json", params: params
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
expect(User.where(username: 'eviltrout').exists?).to eq(true)
expect do
post "/finish-installation/register.json", params: params
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
expect(response).to be_redirect
expect(User.where(username: 'eviltrout').exists?).to eq(true)
end
end
end
end