mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:30:01 +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
|
email = params[:email].strip
|
||||||
raise Discourse::InvalidParameters.new unless @allowed_emails.include?(email)
|
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.email = email
|
||||||
@user.username = params[:username]
|
@user.username = params[:username]
|
||||||
|
@ -23,8 +27,7 @@ class FinishInstallationController < ApplicationController
|
||||||
@user.password_required!
|
@user.password_required!
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
@email_token = @user.email_tokens.unconfirmed.active.first
|
send_signup_email
|
||||||
Jobs.enqueue(:critical_user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
|
|
||||||
return redirect_confirm(@user.email)
|
return redirect_confirm(@user.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,16 +41,22 @@ class FinishInstallationController < ApplicationController
|
||||||
def resend_email
|
def resend_email
|
||||||
@email = session[:registered_email]
|
@email = session[:registered_email]
|
||||||
@user = User.find_by_email(@email)
|
@user = User.find_by_email(@email)
|
||||||
if @user.present?
|
send_signup_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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
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)
|
def redirect_confirm(email)
|
||||||
session[:registered_email] = email
|
session[:registered_email] = email
|
||||||
redirect_to(finish_installation_confirm_email_path)
|
redirect_to(finish_installation_confirm_email_path)
|
||||||
|
|
|
@ -68,18 +68,40 @@ describe FinishInstallationController do
|
||||||
expect(response).not_to be_redirect
|
expect(response).not_to be_redirect
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers the admin when the email is in the list" do
|
context "working params" do
|
||||||
expect do
|
let(:params) do
|
||||||
post "/finish-installation/register.json", params: {
|
{
|
||||||
email: 'robin@example.com',
|
email: 'robin@example.com',
|
||||||
username: 'eviltrout',
|
username: 'eviltrout',
|
||||||
password: 'disismypasswordokay'
|
password: 'disismypasswordokay'
|
||||||
}
|
}
|
||||||
end.to change { Jobs::CriticalUserEmail.jobs.size }.by(1)
|
end
|
||||||
|
|
||||||
expect(response).to be_redirect
|
it "registers the admin when the email is in the list" do
|
||||||
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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user