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) { // Display $textToDisplay = <<<EOT <div id="sidebar_page_sidebar"> <h3 class="notable">{$this->user->getDisplayName()}</h3> <p><img src="{$this->user->getAvatarUrl()}" style="max-width: 95%" /></p> {$this->get_edit_links_html($website)} </div> <div id="sidebar_page_content"> {$this->get_status_html($website)} {$this->get_articles_html($website)} {$this->get_comments_html($website)} </div> EOT; return $textToDisplay; }
/** * 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; }
/** Gets the links for the bottom of the page */ public function get_account_links_html(Website $website) { $textToDisplay = ""; if ($this->editing_someone_else) { // Editing someone else, don't show "My account" link $textToDisplay .= <<<EOT <p> <a class="arrow" href="{$website->getUrlPage("account", $this->user->getId())}"> {$website->tReplaced("users.profile_page_of", $this->user->getDisplayName())} </a><br /> <a class="arrow" href="{$website->getUrlPage("account_management")}"> {$website->t("main.account_management")} </a> EOT; } else { $textToDisplay .= '<p><a class="arrow" href="' . $website->getUrlPage("account") . '">' . $website->t("main.my_account") . "</a>\n"; if ($website->isLoggedInAsStaff(true)) { $textToDisplay .= '<br /><a class="arrow" href="' . $website->getUrlPage("account_management") . '">' . $website->t("main.account_management") . "</a>\n"; } $textToDisplay .= "</p>"; } return $textToDisplay; }
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; }
/** * Sets the author of this article to the given user. * @param User $user The user. */ public function setAuthor(User $user) { $this->author = $user->getDisplayName(); $this->authorId = $user->getId(); $this->updateLastEdited(); }