0
0
Fork 0

Add support for invite codes in the registration API (#27805)

This commit is contained in:
Claire 2023-11-13 14:27:00 +01:00 committed by GitHub
parent 5bca5c4c5b
commit 07a4059901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 158 additions and 78 deletions

View file

@ -1,12 +1,14 @@
# frozen_string_literal: true
class AppSignUpService < BaseService
include RegistrationHelper
def call(app, remote_ip, params)
@app = app
@remote_ip = remote_ip
@params = params
raise Mastodon::NotPermittedError unless allowed_registrations?
raise Mastodon::NotPermittedError unless allowed_registration?(remote_ip, invite)
ApplicationRecord.transaction do
create_user!
@ -34,8 +36,12 @@ class AppSignUpService < BaseService
)
end
def invite
Invite.find_by(code: @params[:invite_code]) if @params[:invite_code].present?
end
def user_params
@params.slice(:email, :password, :agreement, :locale, :time_zone)
@params.slice(:email, :password, :agreement, :locale, :time_zone, :invite_code)
end
def account_params
@ -45,24 +51,4 @@ class AppSignUpService < BaseService
def invite_request_params
{ text: @params[:reason] }
end
def allowed_registrations?
registrations_open? && !single_user_mode? && !omniauth_only? && !ip_blocked?
end
def registrations_open?
Setting.registrations_mode != 'none'
end
def single_user_mode?
Rails.configuration.x.single_user_mode
end
def omniauth_only?
ENV['OMNIAUTH_ONLY'] == 'true'
end
def ip_blocked?
IpBlock.where(severity: :sign_up_block).where('ip >>= ?', @remote_ip.to_s).exists?
end
end