mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
UX: Wizard resends activation email when user exists
This commit is contained in:
parent
d1607a387a
commit
17dc8f2490
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user