Move user db creation to service
This commit is contained in:
@@ -94,14 +94,15 @@ class SignupController < ApplicationController
|
||||
end
|
||||
|
||||
def complete_signup
|
||||
@user.save!
|
||||
session[:new_user] = nil
|
||||
session[:validation_error] = nil
|
||||
|
||||
CreateAccount.call(
|
||||
username: @user.cn,
|
||||
domain: "kosmos.org",
|
||||
email: @user.email,
|
||||
password: @user.password
|
||||
password: @user.password,
|
||||
invitation: @invitation
|
||||
)
|
||||
|
||||
@invitation.update! invited_user_id: @user.id, used_at: DateTime.now
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
class CreateAccount < ApplicationService
|
||||
def initialize(args)
|
||||
@username = args[:username]
|
||||
@email = args[:email]
|
||||
@password = args[:password]
|
||||
@username = args[:username]
|
||||
@domain = args[:ou] || "kosmos.org"
|
||||
@email = args[:email]
|
||||
@password = args[:password]
|
||||
@invitation = args[:invitation]
|
||||
end
|
||||
|
||||
def call
|
||||
create_user_in_database
|
||||
add_ldap_document
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_user_in_database
|
||||
User.create!(
|
||||
cn: @username,
|
||||
ou: @domain,
|
||||
email: @email,
|
||||
password: @password,
|
||||
password_confirmation: @password
|
||||
)
|
||||
end
|
||||
|
||||
def add_ldap_document
|
||||
dn = "cn=#{@username},ou=kosmos.org,cn=users,dc=kosmos,dc=org"
|
||||
attr = {
|
||||
|
||||
Reference in New Issue
Block a user