Example #1
0
 /**
  * Make sure username is valid
  * Make sure it's not already in use
  *
  * @return object $this
  */
 protected function validateUsername()
 {
     $username = strtolower($this->getSubmittedValue('username'));
     if (false === Validate::username($username)) {
         $this->setError('username', 'This username is invalid. Username must contain only letters, numbers and a hyphen and MUST start and end with letter or number and MUST be at least 3 characters long');
     }
     $aReserved = \Lampcms\getReservedNames();
     if (in_array($username, $aReserved)) {
         $this->setError('username', 'This username is already in use');
     }
     $a = $this->Registry->Mongo->USERS->findOne(array('username_lc' => $username));
     if (!empty($a)) {
         $this->setError('username', 'This username is already in use');
     }
     return $this;
 }
Example #2
0
    /**
     * @todo check that this username does not already
     *       exist
     *
     * @throws \Lampcms\FormException is username is invalid or already taken
     *
     * @return object $this
     */
    protected function checkUsername()
    {
        if (empty($this->Request['username'])) {
            return $this;
        }
        /**
         * If user has not changed suggested username than
         * we don't have to worry about validating it
         */
        if ($this->Request['username'] === $this->Registry->Viewer->username) {
            return $this;
        }
        if (false === Validate::username($this->Request['username'])) {
            throw new \Lampcms\FormException('@@Invalid username. Username can only contain English letters, numbers and a hyphen (but cannot start or end with the hyphen)@@', 'username');
        }
        $aReserved = \Lampcms\getReservedNames();
        $username = \mb_strtolower($this->Request['username']);
        $aUser = $this->Registry->Mongo->USERS->findOne(array(Schema::USERNAME_LOWERCASE => $username));
        if (!empty($aUser) || in_array($username, $aReserved)) {
            throw new \Lampcms\FormException('@@Someone else is already using this username@@. <br>
			@@Please choose a different username and resubmit the form@@', 'username');
        }
        /**
         * Need to set $this->username because
         * it's used in sendActivationEmail()
         */
        $this->username = $this->Request['username'];
        return $this;
    }