summaryrefslogtreecommitdiffstats
path: root/app/controllers/api/v1/invites_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/api/v1/invites_controller.rb')
-rw-r--r--app/controllers/api/v1/invites_controller.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/controllers/api/v1/invites_controller.rb b/app/controllers/api/v1/invites_controller.rb
new file mode 100644
index 00000000000..ea17ba74038
--- /dev/null
+++ b/app/controllers/api/v1/invites_controller.rb
@@ -0,0 +1,30 @@
+# 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