2016-10-18 11:44:25 -04:00
|
|
|
class FinishInstallationController < ApplicationController
|
|
|
|
skip_before_filter :check_xhr, :preload_json, :redirect_to_login_if_required
|
|
|
|
layout 'finish_installation'
|
|
|
|
|
2016-10-21 11:34:19 -04:00
|
|
|
before_filter :ensure_no_admins, except: ['confirm_email', 'resend_email']
|
2016-10-18 11:44:25 -04: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)
|
|
|
|
|
|
|
|
return redirect_confirm(email) if User.where(email: email).exists?
|
|
|
|
|
|
|
|
@user.email = email
|
|
|
|
@user.username = params[:username]
|
|
|
|
@user.password = params[:password]
|
|
|
|
@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)
|
|
|
|
return redirect_confirm(@user.email)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_email
|
|
|
|
@email = session[:registered_email]
|
|
|
|
end
|
|
|
|
|
2016-10-21 11:34:19 -04:00
|
|
|
def resend_email
|
|
|
|
@email = session[:registered_email]
|
|
|
|
@user = User.where(email: @email).first
|
|
|
|
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
|
|
|
|
|
2016-10-18 11:44:25 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
def redirect_confirm(email)
|
|
|
|
session[:registered_email] = email
|
|
|
|
redirect_to(finish_installation_confirm_email_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_allowed_emails
|
|
|
|
return [] unless GlobalSetting.respond_to?(:developer_emails) && GlobalSetting.developer_emails.present?
|
|
|
|
GlobalSetting.developer_emails.split(",").map(&:strip)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_no_admins
|
2016-12-07 11:10:08 -05:00
|
|
|
preload_anonymous_data
|
2016-10-18 11:44:25 -04:00
|
|
|
raise Discourse::InvalidAccess.new unless SiteSetting.has_login_hint?
|
|
|
|
end
|
|
|
|
end
|