app_sign_up_service.rb 1.1 KB

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class AppSignUpService < BaseService
  3. def call(app, remote_ip, 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, sign_up_ip: remote_ip, 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