about summary refs log tree commit diff
path: root/app/services/setup_local_account_service.rb
blob: a5ef689969388d35a2ed57d500b6a9bce5fbada9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class SetupLocalAccountService < BaseService
  # Setup an account for a new user instance by generating
  # an RSA key pair and a profile
  # @param [User] user Unsaved user instance
  # @param [String] username
  def call(user, username)
    user.build_account

    user.account.username = username
    user.account.domain   = nil

    keypair = OpenSSL::PKey::RSA.new(2048)
    user.account.private_key = keypair.to_pem
    user.account.public_key  = keypair.public_key.to_pem

    user.save!
  end
end