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.

39 lines
974 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.build_account if resource.account.nil?
  10. end
  11. def configure_sign_up_params
  12. devise_parameter_sanitizer.permit(:sign_up) do |u|
  13. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation)
  14. end
  15. end
  16. def after_sign_up_path_for(_resource)
  17. new_user_session_path
  18. end
  19. def after_inactive_sign_up_path_for(_resource)
  20. new_user_session_path
  21. end
  22. def check_enabled_registrations
  23. redirect_to root_path if Rails.configuration.x.single_user_mode || !Setting.open_registrations
  24. end
  25. private
  26. def determine_layout
  27. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  28. end
  29. end