registrations_controller.rb 987 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class Auth::RegistrationsController < Devise::RegistrationsController
4
  layout :determine_layout
5

6
  before_action :check_enabled_registrations, only: [:new, :create]
Eugen Rochko's avatar
Eugen Rochko committed
7
  before_action :configure_sign_up_params, only: [:create]
8 9 10 11 12

  protected

  def build_resource(hash = nil)
    super(hash)
13
    resource.locale = I18n.locale
Eugen Rochko's avatar
Eugen Rochko committed
14
    resource.build_account if resource.account.nil?
15 16 17
  end

  def configure_sign_up_params
Eugen Rochko's avatar
Eugen Rochko committed
18 19
    devise_parameter_sanitizer.permit(:sign_up) do |u|
      u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation)
20 21 22
    end
  end

23
  def after_sign_up_path_for(_resource)
24
    new_user_session_path
25
  end
Eugen Rochko's avatar
Eugen Rochko committed
26

27 28 29 30
  def after_inactive_sign_up_path_for(_resource)
    new_user_session_path
  end

31
  def check_enabled_registrations
32
    redirect_to root_path if single_user_mode? || !Setting.open_registrations
Eugen Rochko's avatar
Eugen Rochko committed
33
  end
34

35
  private
36

37 38 39
  def determine_layout
    %w(edit update).include?(action_name) ? 'admin' : 'auth'
  end
40
end