registrations_controller.rb 1.12 KB
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
  before_action :set_sessions, only: [:edit, :update]
9

10 11 12 13
  def destroy
    not_found
  end

14 15 16 17
  protected

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

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

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

32 33 34 35
  def after_inactive_sign_up_path_for(_resource)
    new_user_session_path
  end

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

40
  private
41

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

  def set_sessions
    @sessions = current_user.session_activations
  end
49
end