diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php index 279afc92..10e26b90 100644 --- a/src/app/Jobs/User/CreateJob.php +++ b/src/app/Jobs/User/CreateJob.php @@ -1,123 +1,127 @@ isDeleted()`), or * * the user is actually deleted (`$user->deleted_at`), or * * the user is already marked as ready in LDAP (`$user->isLdapReady()`). */ class CreateJob extends UserJob { /** @var int Enable waiting for a user record to exist */ protected $waitForUser = 5; /** * Execute the job. * * @return void * * @throws \Exception */ public function handle() { $user = $this->getUser(); + \Log::info("Handling create job"); if (!$user) { + \Log::info("User not found"); return; } if ($user->role) { + \Log::info("Ignoring user with a role"); // Admins/resellers don't reside in LDAP (for now) return; } if ($user->email == \config('services.imap.admin_login')) { + \Log::info("Ignoring imap admin"); // Ignore Cyrus admin account return; } // sanity checks if ($user->isDeleted()) { $this->fail(new \Exception("User {$this->userId} is marked as deleted.")); return; } if ($user->trashed()) { $this->fail(new \Exception("User {$this->userId} is actually deleted.")); return; } $withLdap = \config('app.with_ldap'); // see if the domain is ready $domain = $user->domain(); if (!$domain) { $this->fail(new \Exception("The domain for {$this->userId} does not exist.")); return; } if ($domain->isDeleted()) { $this->fail(new \Exception("The domain for {$this->userId} is marked as deleted.")); return; } if ($withLdap && !$domain->isLdapReady()) { $this->release(60); return; } if (\config('abuse.suspend_enabled') && !$user->isSuspended()) { $code = \Artisan::call("user:abuse-check {$this->userId}"); if ($code == 2) { \Log::info("Suspending user due to suspected abuse: {$this->userId} {$user->email}"); \App\EventLog::createFor($user, \App\EventLog::TYPE_SUSPENDED, "Suspected spammer"); $user->status |= \App\User::STATUS_SUSPENDED; } } if ($withLdap && !$user->isLdapReady()) { \App\Backends\LDAP::createUser($user); $user->status |= \App\User::STATUS_LDAP_READY; $user->save(); } if (!$user->isImapReady()) { if (\config('app.with_imap')) { if (!\App\Backends\IMAP::createUser($user)) { throw new \Exception("Failed to create mailbox for user {$this->userId}."); } } else { if (!\App\Backends\IMAP::verifyAccount($user->email)) { $this->release(15); return; } } $user->status |= \App\User::STATUS_IMAP_READY; } // FIXME: Should we ignore exceptions on this operation or introduce DAV_READY status? \App\Backends\DAV::initDefaultFolders($user); // Make user active in non-mandate mode only if ( !($wallet = $user->wallet()) || !($plan = $user->wallet()->plan()) || $plan->mode != \App\Plan::MODE_MANDATE ) { $user->status |= \App\User::STATUS_ACTIVE; } $user->save(); } }