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; }
public function getPageContent(Website $website, Request $request) { $show_form = true; $textToDisplay = ""; if ($request->hasRequestValue("email")) { // Sent $email = $request->getRequestString("email"); if (Validate::email($email)) { // Valid email $this->user->setEmail($email); $userRepo = $website->getAuth()->getUserRepository(); $userRepo->save($this->user); // Saved $textToDisplay .= '<p>' . $website->t("users.email") . ' ' . $website->t("editor.is_changed") . '</p>'; // Don't show form $show_form = false; } else { // Invalid email $website->addError($website->t("users.email") . ' ' . Validate::getLastError($website)); $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.email", true) . '</em></p>'; } } // Show form if ($show_form) { // Text above form $textToDisplay .= "<p>" . $website->t("users.email.edit.explained") . "</p>\n"; if ($this->editing_someone_else) { $textToDisplay .= "<p><em>" . $website->tReplaced("users.edit_other", $this->user->getDisplayName()) . "</em></p>\n"; } // Form itself $email = htmlSpecialChars($request->getRequestString("email", $this->user->getEmail())); $textToDisplay .= <<<EOT <form action="{$website->getUrlMain()}" method="post"> <p> <label for="email">{$website->t('users.email')}:</label><br /><input type="text" id="email" name="email" value="{$email}"/><br /> </p> <p> <input type="hidden" name="id" value="{$this->user->getId()}" /> <input type="hidden" name="p" value="edit_email" /> <input type="submit" value="{$website->t('users.email.edit')} " class="button" /> </p> </form> EOT; } // Links $textToDisplay .= $this->get_account_links_html($website); return $textToDisplay; }
/** * Validates a comment for saving to the database. * @param Comment $comment The comment. * @param Text $text Errors go here. * @return boolean True if the comment is valid, false otherwise. */ public function validateComment(Comment $comment, Text $text) { $valid = true; if (!Validate::stringLength($comment->getBodyRaw(), Comment::BODY_MIN_LENGTH, Comment::BODY_MAX_LENGTH)) { $text->addError($text->t("comments.comment") . " " . Validate::getLastError($text)); $valid = false; } if ($comment->isByVisitor()) { if (!Validate::email($comment->getUserEmail())) { $text->addError($text->t("users.email") . " " . Validate::getLastError($text)); $valid = false; } if (!Validate::displayName($comment->getUserDisplayName())) { $text->addError($text->t("users.name") . " " . Validate::getLastError($text)); $valid = false; } } return $valid; }
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; }