Exemplo n.º 1
0
 /**
  * Validate a validation code's validity, validly.
  *
  * @param Records $records
  * @param string  $code
  */
 public function validateCode(Records $records, $code)
 {
     $this->code = $code;
     if (strlen($code) !== 40) {
         $this->message = 'Invalid code';
         return;
     }
     // Get the verification key meta entity
     $metaEntities = $records->getAccountMetaValues(self::KEY_NAME, $code);
     if ($metaEntities === false) {
         $this->throwException(new AccountVerificationException('Stored meta code not found', AccountVerificationException::MISSING_META));
     }
     /** @var Storage\Entity\AccountMeta $metaEntity */
     $metaEntity = reset($metaEntities);
     if ($metaEntity === false) {
         $this->throwException(new AccountVerificationException('Stored meta code previously removed.', AccountVerificationException::REMOVED_META));
     }
     $guid = $metaEntity->getGuid();
     // Get the account and set it as verified
     $this->account = $records->getAccountByGuid($guid);
     if ($this->account === false) {
         $this->throwException(new AccountVerificationException('Missing account record.', AccountVerificationException::MISSING_ACCOUNT));
     }
     $this->account->setVerified(true);
     $records->saveAccount($this->account);
     // Remove meta record
     $records->deleteAccountMeta($metaEntity);
     $this->success = true;
     $this->message = 'Account validated!';
 }