예제 #1
0
 private function validateInput(User $user, $password1, $password2, UserRepository $userRepo, Text $text)
 {
     $valid = true;
     if (!Validate::username($user->getUsername())) {
         $valid = false;
         $text->addError($text->t("users.the_username") . " " . Validate::getLastError($text));
     }
     if (!Validate::displayName($user->getDisplayName())) {
         $valid = false;
         $text->addError($text->t("users.the_display_name") . " " . Validate::getLastError($text));
     }
     if (!Validate::password($password1, $password2)) {
         $valid = false;
         $text->addError($text->t("users.the_password") . " " . Validate::getLastError($text));
     }
     if (!Validate::email($user->getEmail())) {
         $valid = false;
         $text->addError($text->t("users.the_email") . " " . Validate::getLastError($text));
     }
     if ($userRepo->isUsernameInUse($user->getUsername())) {
         // User with that name already exists
         $valid = false;
         $text->addError($text->tReplaced("errors.already_in_use_on_this_site", $text->t("users.the_username")));
     }
     if (!empty($user->getEmail()) && $userRepo->isEmailInUse($user->getEmail())) {
         // User with that email already exists
         $valid = false;
         $text->addError($text->tReplaced("errors.already_in_use_on_this_site", $text->t("users.the_email")));
     }
     return $valid;
 }
예제 #2
0
파일: Comment.php 프로젝트: rutgerkok/rCMS
 /**
  * Creates a new comment for the given user. This method will succeed even
  * if the given article doesn't allow comments.
  * @param User $user The author of the comment.
  * @param Article $article The article that is commented on.
  * @param string $text The comment of the user.
  * @return Comment The comment.
  */
 public static function createForUser(User $user, Article $article, $text)
 {
     $comment = new Comment(0);
     $comment->articleId = $article->getId();
     $comment->userId = $user->getId();
     $comment->userName = $user->getUsername();
     $comment->userDisplayName = $user->getDisplayName();
     $comment->userEmail = $user->getEmail();
     $comment->userRank = $user->getRank();
     $comment->created = new DateTime();
     $comment->body = (string) $text;
     return $comment;
 }
예제 #3
0
 private function validateInput(User $user, $password, Authentication $auth, UserRepository $userRepo, Text $text)
 {
     $valid = true;
     if (!Validate::username($user->getUsername())) {
         $valid = false;
         $text->addError($text->t("users.the_username") . " " . Validate::getLastError($text));
     }
     if (!Validate::displayName($user->getDisplayName())) {
         $valid = false;
         $text->addError($text->t("users.the_display_name") . " " . Validate::getLastError($text));
     }
     if (!Validate::password($password, $password)) {
         $valid = false;
         $text->addError($text->t("users.the_password") . " " . Validate::getLastError($text));
     }
     if (!Validate::email($user->getEmail())) {
         $valid = false;
         $text->addError($text->t("users.the_email") . " " . Validate::getLastError($text));
     }
     if ($userRepo->isUsernameInUse($user->getUsername())) {
         // User with that name already exists
         $valid = false;
         $text->addError($text->tReplaced("errors.already_in_use_on_this_site", $text->t("users.the_username")));
     }
     if (!empty($user->getEmail()) && $userRepo->isEmailInUse($user->getEmail())) {
         // User with that email already exists
         $valid = false;
         $text->addError($text->tReplaced("errors.already_in_use_on_this_site", $text->t("users.the_email")));
     }
     if (!$auth->isValidRankForAccounts($user->getRank())) {
         // Invlaid rank
         $valid = false;
         $text->addError($text->t("users.the_rank") . " " . $text->t("errors.is_invalid"));
     }
     return $valid;
 }