about summary refs log tree commit diff
path: root/app/services/app_sign_up_service.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-01-02 13:45:18 +0100
committerThibaut Girka <thib@sitedethib.com>2019-01-02 15:36:53 +0100
commit571d219bb917cefcca7419a0ad4e3889689d5f6a (patch)
tree6ab91adcb2c164fd027708e58f5fb96c52474007 /app/services/app_sign_up_service.rb
parentb300948526d967aaf5608c93546ee0d54940c0ef (diff)
parent66436d08959998be20c6c6bf631177d8c1f3e0d1 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts manually resolved:
- app/services/post_status_service.rb
- config/locales/simple_form.pl.yml
- config/routes.rb
- config/webpack/loaders/sass.js
- config/webpack/shared.js
- package.json
- yarn.lock
Diffstat (limited to 'app/services/app_sign_up_service.rb')
-rw-r--r--app/services/app_sign_up_service.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/services/app_sign_up_service.rb b/app/services/app_sign_up_service.rb
new file mode 100644
index 000000000..1878587e8
--- /dev/null
+++ b/app/services/app_sign_up_service.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+class AppSignUpService < BaseService
+  def call(app, params)
+    return unless allowed_registrations?
+
+    user_params    = params.slice(:email, :password, :agreement)
+    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
+
+  private
+
+  def allowed_registrations?
+    Setting.open_registrations && !Rails.configuration.x.single_user_mode
+  end
+end