2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-18 23:44:25 +08:00
|
|
|
class FinishInstallationController < ApplicationController
|
2024-06-25 19:32:18 +08:00
|
|
|
skip_before_action :check_xhr,
|
|
|
|
:preload_json,
|
|
|
|
:redirect_to_login_if_required,
|
|
|
|
:redirect_to_profile_if_required
|
2016-10-18 23:44:25 +08:00
|
|
|
layout "finish_installation"
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
before_action :ensure_no_admins, except: %w[confirm_email resend_email]
|
2016-10-18 23:44:25 +08:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def register
|
|
|
|
@allowed_emails = find_allowed_emails
|
|
|
|
|
|
|
|
@user = User.new
|
|
|
|
if request.post?
|
|
|
|
email = params[:email].strip
|
2024-05-27 18:27:13 +08:00
|
|
|
raise Discourse::InvalidParameters.new if @allowed_emails.exclude?(email)
|
2016-10-18 23:44:25 +08:00
|
|
|
|
2018-08-22 01:11:18 +08:00
|
|
|
if existing_user = User.find_by_email(email)
|
|
|
|
@user = existing_user
|
|
|
|
send_signup_email
|
|
|
|
return redirect_confirm(email)
|
|
|
|
end
|
2016-10-18 23:44:25 +08:00
|
|
|
|
|
|
|
@user.email = email
|
|
|
|
@user.username = params[:username]
|
|
|
|
@user.password = params[:password]
|
|
|
|
@user.password_required!
|
|
|
|
|
|
|
|
if @user.save
|
2018-08-22 13:45:24 +08:00
|
|
|
@user.change_trust_level!(1) if @user.trust_level < 1
|
2018-08-22 01:11:18 +08:00
|
|
|
send_signup_email
|
2019-12-10 08:48:27 +08:00
|
|
|
redirect_confirm(@user.email)
|
2016-10-18 23:44:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_email
|
|
|
|
@email = session[:registered_email]
|
|
|
|
end
|
|
|
|
|
2016-10-21 23:34:19 +08:00
|
|
|
def resend_email
|
|
|
|
@email = session[:registered_email]
|
2017-04-27 02:47:36 +08:00
|
|
|
@user = User.find_by_email(@email)
|
2018-08-22 01:11:18 +08:00
|
|
|
send_signup_email if @user.present?
|
2016-10-21 23:34:19 +08:00
|
|
|
end
|
|
|
|
|
2016-10-18 23:44:25 +08:00
|
|
|
protected
|
|
|
|
|
2018-08-22 01:11:18 +08:00
|
|
|
def send_signup_email
|
2021-11-25 15:34:39 +08:00
|
|
|
return if @user.active && @user.email_confirmed?
|
2018-08-22 01:11:18 +08:00
|
|
|
|
2021-11-25 15:34:39 +08:00
|
|
|
email_token = @user.email_tokens.create!(email: @user.email, scope: EmailToken.scopes[:signup])
|
|
|
|
EmailToken.enqueue_signup_email(email_token)
|
2018-08-22 01:11:18 +08:00
|
|
|
end
|
|
|
|
|
2016-10-18 23:44:25 +08:00
|
|
|
def redirect_confirm(email)
|
|
|
|
session[:registered_email] = email
|
|
|
|
redirect_to(finish_installation_confirm_email_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_allowed_emails
|
|
|
|
unless GlobalSetting.respond_to?(:developer_emails) && GlobalSetting.developer_emails.present?
|
|
|
|
return []
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
2016-10-18 23:44:25 +08:00
|
|
|
GlobalSetting.developer_emails.split(",").map(&:strip)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_no_admins
|
2016-12-08 00:10:08 +08:00
|
|
|
preload_anonymous_data
|
2016-10-18 23:44:25 +08:00
|
|
|
raise Discourse::InvalidAccess.new unless SiteSetting.has_login_hint?
|
|
|
|
end
|
|
|
|
end
|