2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-18 10:44:25 -05:00
|
|
|
class FinishInstallationController < ApplicationController
|
2017-08-30 23:06:56 -05:00
|
|
|
skip_before_action :check_xhr, :preload_json, :redirect_to_login_if_required
|
2016-10-18 10:44:25 -05:00
|
|
|
layout 'finish_installation'
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
before_action :ensure_no_admins, except: ['confirm_email', 'resend_email']
|
2016-10-18 10:44:25 -05:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def register
|
|
|
|
@allowed_emails = find_allowed_emails
|
|
|
|
|
|
|
|
@user = User.new
|
|
|
|
if request.post?
|
|
|
|
email = params[:email].strip
|
|
|
|
raise Discourse::InvalidParameters.new unless @allowed_emails.include?(email)
|
|
|
|
|
2018-08-21 12:11:18 -05:00
|
|
|
if existing_user = User.find_by_email(email)
|
|
|
|
@user = existing_user
|
|
|
|
send_signup_email
|
|
|
|
return redirect_confirm(email)
|
|
|
|
end
|
2016-10-18 10:44:25 -05:00
|
|
|
|
|
|
|
@user.email = email
|
|
|
|
@user.username = params[:username]
|
|
|
|
@user.password = params[:password]
|
|
|
|
@user.password_required!
|
|
|
|
|
|
|
|
if @user.save
|
2018-08-22 00:45:24 -05:00
|
|
|
@user.change_trust_level!(1) if @user.trust_level < 1
|
2018-08-21 12:11:18 -05:00
|
|
|
send_signup_email
|
2019-12-09 18:48:27 -06:00
|
|
|
redirect_confirm(@user.email)
|
2016-10-18 10:44:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_email
|
|
|
|
@email = session[:registered_email]
|
|
|
|
end
|
|
|
|
|
2016-10-21 10:34:19 -05:00
|
|
|
def resend_email
|
|
|
|
@email = session[:registered_email]
|
2017-04-26 13:47:36 -05:00
|
|
|
@user = User.find_by_email(@email)
|
2018-08-21 12:11:18 -05:00
|
|
|
send_signup_email if @user.present?
|
2016-10-21 10:34:19 -05:00
|
|
|
end
|
|
|
|
|
2016-10-18 10:44:25 -05:00
|
|
|
protected
|
|
|
|
|
2018-08-21 12:11:18 -05:00
|
|
|
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
|
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
def redirect_confirm(email)
|
|
|
|
session[:registered_email] = email
|
|
|
|
redirect_to(finish_installation_confirm_email_path)
|
|
|
|
end
|
2016-10-18 10:44:25 -05:00
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
def find_allowed_emails
|
|
|
|
return [] unless GlobalSetting.respond_to?(:developer_emails) && GlobalSetting.developer_emails.present?
|
|
|
|
GlobalSetting.developer_emails.split(",").map(&:strip)
|
|
|
|
end
|
2016-10-18 10:44:25 -05:00
|
|
|
|
2018-06-07 00:28:18 -05:00
|
|
|
def ensure_no_admins
|
|
|
|
preload_anonymous_data
|
|
|
|
raise Discourse::InvalidAccess.new unless SiteSetting.has_login_hint?
|
|
|
|
end
|
2016-10-18 10:44:25 -05:00
|
|
|
end
|