2018-07-18 12:03:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-27 05:37:24 -04:00
|
|
|
module Users
|
|
|
|
class CreateService < BaseService
|
2017-08-25 19:15:43 -04:00
|
|
|
include NewUserNotifier
|
|
|
|
|
2017-03-27 05:37:24 -04:00
|
|
|
def initialize(current_user, params = {})
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params.dup
|
|
|
|
end
|
|
|
|
|
2017-04-24 17:12:14 -04:00
|
|
|
def execute(skip_authorization: false)
|
|
|
|
user = Users::BuildService.new(current_user, params).execute(skip_authorization: skip_authorization)
|
2020-02-14 01:09:03 -05:00
|
|
|
reset_token = user.generate_reset_token if user.recently_sent_password_reset?
|
2017-04-13 04:47:52 -04:00
|
|
|
|
2020-02-14 01:09:03 -05:00
|
|
|
after_create_hook(user, reset_token) if user.save
|
2017-03-27 05:37:24 -04:00
|
|
|
|
|
|
|
user
|
|
|
|
end
|
2020-02-14 01:09:03 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def after_create_hook(user, reset_token)
|
|
|
|
notify_new_user(user, reset_token)
|
|
|
|
end
|
2017-03-27 05:37:24 -04:00
|
|
|
end
|
|
|
|
end
|
2020-02-14 01:09:03 -05:00
|
|
|
|
|
|
|
Users::CreateService.prepend_if_ee('EE::Users::CreateService')
|