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 (isset($_REQUEST["display_name"])) { // Sent $display_name = $request->getRequestString("display_name"); if (Validate::displayName($display_name)) { // Valid display_name $this->user->setDisplayName($display_name); $userRepo = $website->getAuth()->getUserRepository(); $userRepo->save($this->user); // Saved $textToDisplay .= '<p>' . $website->t("users.display_name") . ' ' . $website->t("editor.is_changed") . '</p>'; // Don't show form $show_form = false; } else { // Invalid display_name $website->addError($website->t("users.display_name") . ' ' . Validate::getLastError($website)); $textToDisplay .= '<p><em>' . $website->tReplacedKey("errors.your_input_has_not_been_changed", "users.display_name", true) . '</em></p>'; } } // Show form if ($show_form) { // Text above form $textToDisplay .= "<p>" . $website->t("users.display_name.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 $display_name = isset($_POST['display_name']) ? htmlSpecialChars($_POST['display_name']) : $this->user->getDisplayName(); $textToDisplay .= <<<EOT <p>{$website->t("main.fields_required")}</p> <form action="{$website->getUrlMain()}" method="post"> <p> <label for="display_name">{$website->t('users.display_name')}:</label><span class="required">*</span><br /> <input type="text" id="display_name" name="display_name" value="{$display_name}"/><br /> </p> <p> <input type="hidden" name="id" value="{$this->user->getId()}" /> <input type="hidden" name="p" value="edit_display_name" /> <input type="submit" value="{$website->t('users.display_name.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; }