protected function validateDob() { $dob = $this->Registry->Request['dob']; if (!empty($dob) && !Validate::validateDob($dob)) { $this->setError('dob', '@@Invalid format of date string OR invalid values@@'); } return $this; }
/** * Draws a border around the current * active GD resource image * * @param int $intBorderWidth width of border to draw * * @return object $this */ protected function addBorder($intBorderWidth = 1) { Validate::type($this->hdlWork, array('resource' => 'gd'), __METHOD__); if ($intBorderWidth > 1) { \imagesetthickness($this->hdlWork, $intBorderWidth); } $resBorderColor = \imagecolorallocate($this->hdlWork, 0, 0, 0); // default is black color border $x2 = \imagesx($this->hdlWork) - 1; $y2 = \imagesy($this->hdlWork) - 1; $bool1 = \imageline($this->hdlWork, 0, 0, 0, $y2, $resBorderColor); $bool2 = \imageline($this->hdlWork, 0, $y2, $x2, $y2, $resBorderColor); $bool3 = \imageline($this->hdlWork, $x2, 0, 0, 0, $resBorderColor); $bool4 = \imageline($this->hdlWork, $x2, $y2, $x2, 0, $resBorderColor); d('imageline results: ' . $bool1 . ' ' . $bool2 . ' ' . $bool3 . ' ' . $bool4); return $this; }
/** * Validation to check that user * with this username or email address * exists in the database * If user exists, set the $this->forgottenUid * to the value of this user's id * * @return bool true if user found, otherwise false * and in case of false also sets form errors * so that user will see the form with errors */ protected function validateUser() { $this->login = \mb_strtolower($this->Form->getSubmittedValue('login')); d('$this->login: '******'cp'); $this->byEmail = true; $aEmail = $this->Registry->Mongo->EMAILS->findOne(array('email' => $this->login)); if (empty($aEmail)) { $this->Form->setError('login', 'No user with this email address'); return false; } d('$aEmail: ' . print_r($aEmail, 1)); $aResult = $this->Registry->Mongo->USERS->findOne(array('_id' => (int) $aEmail['i_uid'])); } else { if (false === \Lampcms\Validate::username($this->login)) { d('cp'); $this->Form->setError('login', 'This username is invalid'); return false; } $aResult = $this->Registry->Mongo->USERS->findOne(array('username_lc' => $this->login)); } if (empty($aResult)) { d('cp'); $this->Form->setError('login', 'User Not found'); return false; } /** * @todo * * if 'usertype' == 'email' * then user does not have login * Just test and then throw an exception? * Actually maybe it's better if user could just login * then edit profile and become regular user... * * But how would we do that? We would bacially activate * a user on first login. */ d('$aResult: ' . \print_r($aResult, 1)); /** * If username exists but email does not * such as the case when user is external user who has * not yet provided email address * */ if (empty($aResult['email'])) { throw new \Lampcms\Exception('This is an external account and you have not provided a valid email address for it'); } /** * @todo if user does not have username * then we should use email address instead * user should be able to login using email address! * */ $this->uid = $aResult['_id']; $this->login = !empty($aResult['username']) ? $aResult['username'] : $aResult['email']; $this->emailAddress = $aResult['email']; return true; }
/** * Validate that password is valid * according to rules set in Validate::enforcePwd * * @return $this */ protected function validateNewPassword() { $pwd1 = $this->getSubmittedValue('pwd1'); if (false === Validate::enforcePwd($pwd1)) { $this->setError('pwd1', $this->_('Password must be at least 6 characters long and contain at least one number')); } return $this; }
/** * 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; }
/** * Validate that password is valid * according to rules set in Validate::enforcePwd * * @return $this */ protected function validatePassword() { $pwd1 = $this->getSubmittedValue('password'); if (false === Validate::enforcePwd($pwd1)) { $this->setError('password1', $this->_('Password must be at least 6 characters long and contain at least one number')); } $pwd2 = $this->getSubmittedValue('password1'); if ($pwd1 !== $pwd2) { $this->setError('password2', $this->_('"New password" and "Confirm new password" do not match')); } return $this; }
/** * @todo * Check that this email does not already exist * * @throws \Lampcms\FormException * @return object $this */ protected function validateEmail() { $email = \mb_strtolower($this->Request['email']); if (false === Validate::email($email)) { throw new \Lampcms\FormException('@@Email address@@ ' . $this->Request['email'] . ' @@is invalid@@<br/>@@Please correct it and resubmit the form@@', 'email'); } $ret = $this->Registry->Mongo->EMAILS->findOne(array('email' => $email)); /** * @todo when we have 'join existing account' * form at the bottom then we can also suggest that user * enters username/password to join this "twitter" account * with an existing account */ if (!empty($ret)) { throw new \Lampcms\FormException('<p>Someone else (probably you) is already registered with this email address <p/><p>If you forgot you password, <br/>please use the <a href="{_WEB_ROOT_}/{_remindpwd_}/">This link</a> to request a new password<br/> or use different email address to register a new account</p>', 'email'); } /** * Important to set $this->email * it is used in parent class to createEmailRecord() * as well as to email out the new registration password */ $this->email = $email; return $this; }