registrations_controller.rb 1.28 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
  before_action :set_instance_presenter, only: [:new, :create, :update]
10

11 12 13 14
  def destroy
    not_found
  end

15 16 17 18
  protected

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

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

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

33 34 35 36
  def after_inactive_sign_up_path_for(_resource)
    new_user_session_path
  end

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

41
  private
42

43 44 45 46
  def set_instance_presenter
    @instance_presenter = InstancePresenter.new
  end

47 48 49
  def determine_layout
    %w(edit update).include?(action_name) ? 'admin' : 'auth'
  end
50 51 52 53

  def set_sessions
    @sessions = current_user.session_activations
  end
54
end