The code powering m.abunchtell.com https://m.abunchtell.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

118 行
2.9 KiB

  1. # frozen_string_literal: true
  2. class Auth::RegistrationsController < Devise::RegistrationsController
  3. layout :determine_layout
  4. before_action :set_invite, only: [:new, :create]
  5. before_action :check_enabled_registrations, only: [:new, :create]
  6. before_action :configure_sign_up_params, only: [:create]
  7. before_action :set_sessions, only: [:edit, :update]
  8. before_action :set_instance_presenter, only: [:new, :create, :update]
  9. before_action :set_body_classes, only: [:new, :create, :edit, :update]
  10. before_action :require_not_suspended!, only: [:update]
  11. before_action :set_cache_headers, only: [:edit, :update]
  12. skip_before_action :require_functional!, only: [:edit, :update]
  13. def new
  14. super(&:build_invite_request)
  15. end
  16. def destroy
  17. not_found
  18. end
  19. protected
  20. def update_resource(resource, params)
  21. params[:password] = nil if Devise.pam_authentication && resource.encrypted_password.blank?
  22. super
  23. end
  24. def build_resource(hash = nil)
  25. super(hash)
  26. resource.locale = I18n.locale
  27. resource.invite_code = params[:invite_code] if resource.invite_code.blank?
  28. resource.agreement = true
  29. resource.current_sign_in_ip = request.remote_ip
  30. resource.build_account if resource.account.nil?
  31. end
  32. def configure_sign_up_params
  33. devise_parameter_sanitizer.permit(:sign_up) do |u|
  34. u.permit({ account_attributes: [:username], invite_request_attributes: [:text] }, :email, :password, :password_confirmation, :invite_code)
  35. end
  36. end
  37. def after_sign_up_path_for(_resource)
  38. auth_setup_path
  39. end
  40. def after_sign_in_path_for(_resource)
  41. set_invite
  42. if @invite&.autofollow?
  43. short_account_path(@invite.user.account)
  44. else
  45. super
  46. end
  47. end
  48. def after_inactive_sign_up_path_for(_resource)
  49. new_user_session_path
  50. end
  51. def after_update_path_for(_resource)
  52. edit_user_registration_path
  53. end
  54. def check_enabled_registrations
  55. redirect_to root_path if single_user_mode? || !allowed_registrations?
  56. end
  57. def allowed_registrations?
  58. Setting.registrations_mode != 'none' || @invite&.valid_for_use?
  59. end
  60. def invite_code
  61. if params[:user]
  62. params[:user][:invite_code]
  63. else
  64. params[:invite_code]
  65. end
  66. end
  67. private
  68. def set_instance_presenter
  69. @instance_presenter = InstancePresenter.new
  70. end
  71. def set_body_classes
  72. @body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter'
  73. end
  74. def set_invite
  75. invite = invite_code.present? ? Invite.find_by(code: invite_code) : nil
  76. @invite = invite&.valid_for_use? ? invite : nil
  77. end
  78. def determine_layout
  79. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  80. end
  81. def set_sessions
  82. @sessions = current_user.session_activations
  83. end
  84. def require_not_suspended!
  85. forbidden if current_account.suspended?
  86. end
  87. def set_cache_headers
  88. response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
  89. end
  90. end