Exemplo n.º 1
0
 /**
  * @param User $User
  */
 public function setOwner(User $User)
 {
     if (!$User->getId()) {
         throw new LogicException("Can not set owner without id");
     }
     $this->set(self::FIELD_USER_OWNER, $User);
 }
Exemplo n.º 2
0
 /**
  * Can user like entity?
  * @param User $User
  * @return bool
  */
 public function canUserLikeOrDislike(User $User)
 {
     $userId = $User->getId();
     $whoLiked = $this->getLikedUsersIds();
     $whoDisliked = $this->getDislikedUsersIds();
     return !array_key_exists($userId, $whoLiked) && !array_key_exists($userId, $whoDisliked);
 }
Exemplo n.º 3
0
 /**
  * @param string $email
  * @param string $name
  * @param string $password
  * @return User
  * @throws Exception
  */
 public function registerUser($email, $name, $password)
 {
     if ($this->getIdByName($name)) {
         throw new Exception("User with name {$name} already exists");
     }
     $User = new User([User::FIELD_EMAIL => $email, User::FIELD_NAME => $name, User::FIELD_PASSWORD => password_hash($password, PASSWORD_DEFAULT)]);
     $User->save();
     $this->saveNameIdIndex($name, $User->getId());
     return $User;
 }
 /**
  * Validate a user object.
  *
  * Invokes User::validate(), and additionally tests that the User's email address isn't associated with another User.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     $duplicates = $this->findBy(array('email' => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     return $errors;
 }