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.

49 lines
1.1 KiB

  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. before_action :set_sessions, only: [:edit, :update]
  7. def destroy
  8. not_found
  9. end
  10. protected
  11. def build_resource(hash = nil)
  12. super(hash)
  13. resource.locale = I18n.locale
  14. resource.build_account if resource.account.nil?
  15. end
  16. def configure_sign_up_params
  17. devise_parameter_sanitizer.permit(:sign_up) do |u|
  18. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation)
  19. end
  20. end
  21. def after_sign_up_path_for(_resource)
  22. new_user_session_path
  23. end
  24. def after_inactive_sign_up_path_for(_resource)
  25. new_user_session_path
  26. end
  27. def check_enabled_registrations
  28. redirect_to root_path if single_user_mode? || !Setting.open_registrations
  29. end
  30. private
  31. def determine_layout
  32. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  33. end
  34. def set_sessions
  35. @sessions = current_user.session_activations
  36. end
  37. end