The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

101 lines
2.4 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. def destroy
  11. not_found
  12. end
  13. protected
  14. def update_resource(resource, params)
  15. params[:password] = nil if Devise.pam_authentication && resource.encrypted_password.blank?
  16. super
  17. end
  18. def build_resource(hash = nil)
  19. super(hash)
  20. resource.locale = I18n.locale
  21. resource.invite_code = params[:invite_code] if resource.invite_code.blank?
  22. resource.agreement = true
  23. resource.current_sign_in_ip = request.remote_ip if resource.current_sign_in_ip.nil?
  24. resource.build_account if resource.account.nil?
  25. end
  26. def configure_sign_up_params
  27. devise_parameter_sanitizer.permit(:sign_up) do |u|
  28. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation, :invite_code)
  29. end
  30. end
  31. def after_sign_up_path_for(_resource)
  32. new_user_session_path
  33. end
  34. def after_sign_in_path_for(_resource)
  35. set_invite
  36. if @invite&.autofollow?
  37. short_account_path(@invite.user.account)
  38. else
  39. super
  40. end
  41. end
  42. def after_inactive_sign_up_path_for(_resource)
  43. new_user_session_path
  44. end
  45. def after_update_path_for(_resource)
  46. edit_user_registration_path
  47. end
  48. def check_enabled_registrations
  49. redirect_to root_path if single_user_mode? || !allowed_registrations?
  50. end
  51. def allowed_registrations?
  52. Setting.registrations_mode != 'none' || @invite&.valid_for_use?
  53. end
  54. def invite_code
  55. if params[:user]
  56. params[:user][:invite_code]
  57. else
  58. params[:invite_code]
  59. end
  60. end
  61. private
  62. def set_instance_presenter
  63. @instance_presenter = InstancePresenter.new
  64. end
  65. def set_body_classes
  66. @body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter'
  67. end
  68. def set_invite
  69. @invite = invite_code.present? ? Invite.find_by(code: invite_code) : nil
  70. end
  71. def determine_layout
  72. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  73. end
  74. def set_sessions
  75. @sessions = current_user.session_activations
  76. end
  77. end