summaryrefslogtreecommitdiff
path: root/app/services/users/create_service.rb
blob: 591d88b275efc3043cc1dd36af994d3c278144ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Users
  class CreateService < BaseService
    include NewUserNotifier

    def initialize(current_user, params = {})
      @current_user = current_user
      @params = params.dup
    end

    def execute
      user = build_class.new(current_user, params).execute
      reset_token = user.generate_reset_token if user.recently_sent_password_reset?

      after_create_hook(user, reset_token) if user.save

      user
    end

    private

    def after_create_hook(user, reset_token)
      notify_new_user(user, reset_token)
    end

    def build_class
      # overridden by inheriting classes
      Users::BuildService
    end
  end
end

Users::CreateService.prepend_mod_with('Users::CreateService')