Esempio n. 1
0
 /**
  * @param User $user
  * @param Hasher $hash
  * @param Dispatcher $events
  * @return User
  * @throws Exception
  */
 public function handle(User $user, Hasher $hash, Dispatcher $events)
 {
     $connection = $user->getConnection();
     $connection->beginTransaction();
     //we already have a user with this email.
     try {
         if (!$this->user) {
             $this->user = $user;
             $this->user->email = $this->email;
             $this->user->password = $hash->make($this->password);
             $this->user->save();
         }
         $events->fire(new UserRegistered($this->user, $this->invitation));
         $connection->commit();
         return $this->user;
     } catch (Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }