Add support for invite codes in the registration API (#27805)
This commit is contained in:
parent
5bca5c4c5b
commit
07a4059901
9 changed files with 158 additions and 78 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue