/** * Check for uniqueness of the username * * @param string $username URL encoded username */ public function actionCheckUsername($username) { // is this Ajax? if ($this->request->isAjax()) { // URL decode & filter out username $username = Fari_Escape::text(Fari_Decode::url($username)); if (empty($username)) { $this->renderJson("The username can't be empty."); } else { // alphanumeric only? if (!Fari_Filter::isAlpha($username)) { $this->renderJson("Only alphanumeric characters are allowed."); } else { // do we have a match? if (!$this->accounts->isUsernameUnique($username)) { $this->renderJson("The username \"{$username}\" is unavailable, sorry."); } else { $this->renderJson(''); } } } } else { $this->renderTemplate('error404/javascript'); } }
/** * Format email and name string to build an email ready header. * @param string $email Email address * @param string $name Optional name * @return string */ private function formatEmail($email, $name) { try { // check email validity if (empty($email) or !Fari_Filter::isEmail($email)) { throw new Fari_Exception("\"{$email}\" is not a valid email address."); } else { $email = "<{$email}>"; // have we provided the name? if (!empty($name)) { // only alphanumeric characters allowed if (!Fari_Filter::isAlpha($name)) { throw new Fari_Exception("\"{$name}\" needs to contain only alphanumeric characters."); } else { // prepend name before the email return '"' . $name . '" ' . $email; } } else { // add brackets around the email return $email; } } } catch (Fari_Exception $exception) { $exception->fire(); } }