Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/User/CreateJob.php
Show All 21 Lines | class CreateJob extends UserJob | ||||
* @return void | * @return void | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = $this->getUser(); | $user = $this->getUser(); | ||||
if (!$user) { | |||||
return; | |||||
} | |||||
// sanity checks | // sanity checks | ||||
if ($user->isDeleted()) { | if ($user->isDeleted()) { | ||||
$this->fail(new \Exception("User {$this->userId} is marked as deleted.")); | $this->fail(new \Exception("User {$this->userId} is marked as deleted.")); | ||||
return; | |||||
} | } | ||||
if ($user->deleted_at) { | if ($user->deleted_at) { | ||||
$this->fail(new \Exception("User {$this->userId} is actually deleted.")); | $this->fail(new \Exception("User {$this->userId} is actually deleted.")); | ||||
return; | |||||
} | } | ||||
if ($user->isLdapReady()) { | if ($user->isLdapReady()) { | ||||
$this->fail(new \Exception("User {$this->userId} is already marked as ldap-ready.")); | $this->fail(new \Exception("User {$this->userId} is already marked as ldap-ready.")); | ||||
return; | |||||
} | } | ||||
// see if the domain is ready | // see if the domain is ready | ||||
$domain = $user->domain(); | $domain = $user->domain(); | ||||
if (!$domain) { | if (!$domain) { | ||||
$this->fail(new \Exception("The domain for {$this->userId} does not exist.")); | $this->fail(new \Exception("The domain for {$this->userId} does not exist.")); | ||||
return; | |||||
} | } | ||||
if ($domain->isDeleted()) { | if ($domain->isDeleted()) { | ||||
$this->fail(new \Exception("The domain for {$this->userId} is marked as deleted.")); | $this->fail(new \Exception("The domain for {$this->userId} is marked as deleted.")); | ||||
return; | |||||
} | } | ||||
if (!$domain->isLdapReady()) { | if (!$domain->isLdapReady()) { | ||||
$this->release(60); | $this->release(60); | ||||
return; | return; | ||||
} | } | ||||
\App\Backends\LDAP::createUser($user); | \App\Backends\LDAP::createUser($user); | ||||
$user->status |= \App\User::STATUS_LDAP_READY; | $user->status |= \App\User::STATUS_LDAP_READY; | ||||
$user->save(); | $user->save(); | ||||
} | } | ||||
} | } |