闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class AppSignUpService < BaseService
  3. def call(app, params)
  4. return unless allowed_registrations?
  5. user_params = params.slice(:email, :password, :agreement, :locale)
  6. account_params = params.slice(:username)
  7. invite_request_params = { text: params[:reason] }
  8. user = User.create!(user_params.merge(created_by_application: app, password_confirmation: user_params[:password], account_attributes: account_params, invite_request_attributes: invite_request_params))
  9. Doorkeeper::AccessToken.create!(application: app,
  10. resource_owner_id: user.id,
  11. scopes: app.scopes,
  12. expires_in: Doorkeeper.configuration.access_token_expires_in,
  13. use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
  14. end
  15. private
  16. def allowed_registrations?
  17. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  18. end
  19. end