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

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

Eugen Rochko's avatar
Eugen Rochko committed
6
  before_action :check_single_user_mode
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)
Eugen Rochko's avatar
Eugen Rochko committed
13
    resource.build_account if resource.account.nil?
14 15 16
  end

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

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

26 27 28 29
  def after_inactive_sign_up_path_for(_resource)
    new_user_session_path
  end

Eugen Rochko's avatar
Eugen Rochko committed
30 31 32
  def check_single_user_mode
    redirect_to root_path if Rails.configuration.x.single_user_mode
  end
33 34 35 36 37 38
  
  private
  
  def determine_layout
    %w(edit update).include?(action_name) ? 'admin' : 'auth'
  end
39
end