You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
987 B

  1. # frozen_string_literal: true
  2. class Auth::RegistrationsController < Devise::RegistrationsController
  3. layout :determine_layout
  4. before_action :check_enabled_registrations, only: [:new, :create]
  5. before_action :configure_sign_up_params, only: [:create]
  6. protected
  7. def build_resource(hash = nil)
  8. super(hash)
  9. resource.locale = I18n.locale
  10. resource.build_account if resource.account.nil?
  11. end
  12. def configure_sign_up_params
  13. devise_parameter_sanitizer.permit(:sign_up) do |u|
  14. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation)
  15. end
  16. end
  17. def after_sign_up_path_for(_resource)
  18. new_user_session_path
  19. end
  20. def after_inactive_sign_up_path_for(_resource)
  21. new_user_session_path
  22. end
  23. def check_enabled_registrations
  24. redirect_to root_path if single_user_mode? || !Setting.open_registrations
  25. end
  26. private
  27. def determine_layout
  28. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  29. end
  30. end