registrations_controller.rb 1022 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
  def destroy
    not_found
  end

13 14 15 16
  protected

  def build_resource(hash = nil)
    super(hash)
17
    resource.locale = I18n.locale
Eugen Rochko's avatar
Eugen Rochko committed
18
    resource.build_account if resource.account.nil?
19 20 21
  end

  def configure_sign_up_params
Eugen Rochko's avatar
Eugen Rochko committed
22 23
    devise_parameter_sanitizer.permit(:sign_up) do |u|
      u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation)
24 25 26
    end
  end

27
  def after_sign_up_path_for(_resource)
28
    new_user_session_path
29
  end
Eugen Rochko's avatar
Eugen Rochko committed
30

31 32 33 34
  def after_inactive_sign_up_path_for(_resource)
    new_user_session_path
  end

35
  def check_enabled_registrations
36
    redirect_to root_path if single_user_mode? || !Setting.open_registrations
Eugen Rochko's avatar
Eugen Rochko committed
37
  end
38

39
  private
40

41 42 43
  def determine_layout
    %w(edit update).include?(action_name) ? 'admin' : 'auth'
  end
44
end