mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-14 10:54:27 +00:00
31 lines
824 B
Ruby
31 lines
824 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Api::V1::InvitesController < Api::BaseController
|
|
include RegistrationHelper
|
|
|
|
skip_before_action :require_authenticated_user!
|
|
skip_around_action :set_locale
|
|
|
|
before_action :set_invite
|
|
before_action :check_enabled_registrations!
|
|
|
|
# Override `current_user` to avoid reading session cookies
|
|
def current_user; end
|
|
|
|
def show
|
|
render json: { invite_code: params[:invite_code], instance_api_url: api_v2_instance_url }, status: 200
|
|
end
|
|
|
|
private
|
|
|
|
def set_invite
|
|
@invite = Invite.find_by!(code: params[:invite_code])
|
|
end
|
|
|
|
def check_enabled_registrations!
|
|
return render json: { error: I18n.t('invites.invalid') }, status: 401 unless @invite.valid_for_use?
|
|
|
|
raise Mastodon::NotPermittedError unless allowed_registration?(request.remote_ip, @invite)
|
|
end
|
|
end
|