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.
 
 
 
 

100 lines
2.3 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.build_account if resource.account.nil?
  24. end
  25. def configure_sign_up_params
  26. devise_parameter_sanitizer.permit(:sign_up) do |u|
  27. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation, :invite_code)
  28. end
  29. end
  30. def after_sign_up_path_for(_resource)
  31. new_user_session_path
  32. end
  33. def after_sign_in_path_for(_resource)
  34. set_invite
  35. if @invite&.autofollow?
  36. short_account_path(@invite.user.account)
  37. else
  38. super
  39. end
  40. end
  41. def after_inactive_sign_up_path_for(_resource)
  42. new_user_session_path
  43. end
  44. def after_update_path_for(_resource)
  45. edit_user_registration_path
  46. end
  47. def check_enabled_registrations
  48. redirect_to root_path if single_user_mode? || !allowed_registrations?
  49. end
  50. def allowed_registrations?
  51. Setting.open_registrations || @invite&.valid_for_use?
  52. end
  53. def invite_code
  54. if params[:user]
  55. params[:user][:invite_code]
  56. else
  57. params[:invite_code]
  58. end
  59. end
  60. private
  61. def set_instance_presenter
  62. @instance_presenter = InstancePresenter.new
  63. end
  64. def set_body_classes
  65. @body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter'
  66. end
  67. def set_invite
  68. @invite = invite_code.present? ? Invite.find_by(code: invite_code) : nil
  69. end
  70. def determine_layout
  71. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  72. end
  73. def set_sessions
  74. @sessions = current_user.session_activations
  75. end
  76. end