/**
* 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;
}