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.

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