2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AppSignUpService < BaseService
|
|
|
|
def call(app, params)
|
2020-12-17 06:34:00 +00:00
|
|
|
return unless allowed_registrations?
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
user_params = params.slice(:email, :password, :agreement, :locale)
|
|
|
|
account_params = params.slice(:username)
|
|
|
|
user = User.create!(user_params.merge(created_by_application: app, password_confirmation: user_params[:password], account_attributes: account_params))
|
|
|
|
|
|
|
|
Doorkeeper::AccessToken.create!(application: app,
|
|
|
|
resource_owner_id: user.id,
|
|
|
|
scopes: app.scopes,
|
|
|
|
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
|
|
|
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
|
|
|
|
end
|
2020-12-17 06:34:00 +00:00
|
|
|
|
|
|
|
def allowed_registrations?
|
|
|
|
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
|
|
|
|
end
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|