invites_controller.rb 824 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V1::InvitesController < Api::BaseController
  3. include RegistrationHelper
  4. skip_before_action :require_authenticated_user!
  5. skip_around_action :set_locale
  6. before_action :set_invite
  7. before_action :check_enabled_registrations!
  8. # Override `current_user` to avoid reading session cookies
  9. def current_user; end
  10. def show
  11. render json: { invite_code: params[:invite_code], instance_api_url: api_v2_instance_url }, status: 200
  12. end
  13. private
  14. def set_invite
  15. @invite = Invite.find_by!(code: params[:invite_code])
  16. end
  17. def check_enabled_registrations!
  18. return render json: { error: I18n.t('invites.invalid') }, status: 401 unless @invite.valid_for_use?
  19. raise Mastodon::NotPermittedError unless allowed_registration?(request.remote_ip, @invite)
  20. end
  21. end