logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

registrations_controller.rb (1903B)


  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, :create, :update]
  8. def destroy
  9. not_found
  10. end
  11. protected
  12. def update_resource(resource, params)
  13. params[:password] = nil if Devise.pam_authentication && resource.encrypted_password.blank?
  14. super
  15. end
  16. def build_resource(hash = nil)
  17. super(hash)
  18. resource.locale = I18n.locale
  19. resource.invite_code = params[:invite_code] if resource.invite_code.blank?
  20. resource.build_account if resource.account.nil?
  21. end
  22. def configure_sign_up_params
  23. devise_parameter_sanitizer.permit(:sign_up) do |u|
  24. u.permit({ account_attributes: [:username] }, :email, :password, :password_confirmation, :invite_code)
  25. end
  26. end
  27. def after_sign_up_path_for(_resource)
  28. new_user_session_path
  29. end
  30. def after_inactive_sign_up_path_for(_resource)
  31. new_user_session_path
  32. end
  33. def after_update_path_for(_resource)
  34. edit_user_registration_path
  35. end
  36. def check_enabled_registrations
  37. redirect_to root_path if single_user_mode? || !allowed_registrations?
  38. end
  39. def allowed_registrations?
  40. Setting.open_registrations || (invite_code.present? && Invite.find_by(code: invite_code)&.valid_for_use?)
  41. end
  42. def invite_code
  43. if params[:user]
  44. params[:user][:invite_code]
  45. else
  46. params[:invite_code]
  47. end
  48. end
  49. private
  50. def set_instance_presenter
  51. @instance_presenter = InstancePresenter.new
  52. end
  53. def determine_layout
  54. %w(edit update).include?(action_name) ? 'admin' : 'auth'
  55. end
  56. def set_sessions
  57. @sessions = current_user.session_activations
  58. end
  59. end