/** * Imports an active directory user. * * @param User $user * * @return bool */ public function handle(User $user) { $user = $user->where('email', $this->user->getEmail())->first(); if (!$user instanceof User) { $email = $this->user->getEmail(); $password = str_random(40); $fullName = $this->user->getName(); $user = $this->dispatch(new CreateUser($email, $password, $fullName)); } // Synchronize their AD attributes. $user->from_ad = true; if ($user->isDirty()) { // Check if there's any changed before // firing a save to save on inserts. $user->save(); } return $user; }
/** * Creates a local User from Active Directory * * @param User $user * @param string $password * * @return \Illuminate\Database\Eloquent\Model */ protected function getModelFromAdldap(User $user, $password) { $email = $user->getEmail(); $model = $this->createModel()->newQuery()->where(compact('email'))->first(); if (!$model) { $model = $this->createModel(); $model->email = $email; $model->password = bcrypt($password); } $model = $this->syncModelFromAdldap($user, $model); if ($this->getBindUserToModel()) { $model = $this->bindAdldapToModel($user, $model); } return $model; }
/** * Create User Entity from adUser * * @param Models\User $adUser * * @return null|user */ protected function createUserFromAd(Models\User $adUser) { $user = new User(); $user->fullName = $adUser->getDisplayName(); $user->userName = $adUser->getAccountName(); $user->email = $adUser->getEmail(); $user->phone = $adUser->getTelephoneNumber(); $user->title = $adUser->getTitle(); $user->thumbnail = $adUser->getThumbnailEncoded(); // save user if ($this->userRepository->save($user)) { $userActivity = new UserActivity(); $userActivity->userId = $user->id; $userActivity->type = "createFromAuthDriver"; $userActivity->description = "Auto create from " . $this->getName(); $this->userActivityRepository->save($userActivity); } else { $user = null; } return $user; }