Example #1
0
 public function newUser($name, $email, $inviteCode = false)
 {
     //securitycode is just a random hexnumber
     $securitycode = sha1($name . $email . mt_rand(-54300, 105000) . microtime());
     $this->_dbAdapter->beginTransaction();
     $this->_dbAdapter->query('INSERT INTO ' . $this->_dbAdapter->quoteTableAs($this->_dbTable->getTableName()) . ' (`email`, `name`, `timestamp`, `securitycode`) SELECT ?, ?, CURRENT_TIMESTAMP, ? FROM DUAL WHERE NOT EXISTS (select * from `people` where people.email = ?) ON DUPLICATE KEY UPDATE name=VALUES(name), timestamp=VALUES(timestamp), securitycode=VALUES(securitycode)', array($email, $name, $securitycode, $email));
     if (!empty($inviteCode) && !$this->_registry->isRegistered("inviteCompleteBefore") && !$this->_registry->isRegistered("inviteMultiple")) {
         $invites = Ml_Model_Invites::getInstance();
         $invites->updateStatus($inviteCode, Ml_Model_Invites::USED);
     }
     $this->_dbAdapter->commit();
     return array("name" => $name, "email" => $email, "securitycode" => $securitycode);
 }
Example #2
0
 public function isValid($value, $context = null)
 {
     $registry = Zend_Registry::getInstance();
     if (isset($context['email']) && $context['email'] && mb_strlen($context['email']) <= 60) {
         $signUp = Ml_Model_SignUp::getInstance();
         $emailData = $signUp->getByEmail(mb_strtolower($context['email']));
         if (!$emailData) {
             $registry->set("inviteCompleteBefore", true);
             return true;
         }
     }
     $valueString = (string) $value;
     $this->_setValue($valueString);
     if (mb_strlen($value) > 8) {
         $this->_error(self::INVALID_INVITE);
         return false;
     }
     if (empty($value)) {
         $this->_error(self::EMPTY_INVITE);
         return false;
     }
     $invites = Ml_Model_Invites::getInstance();
     $token = $invites->get($value);
     if (!$token) {
         $this->_error(self::NOTFOUND_INVITE);
         return false;
     }
     if ($token['used'] && $token['used'] != -1) {
         $this->_error(self::USED_INVITE);
         return false;
     }
     //check if the invite code is for 'more than one person'
     if ($token['used'] == -1) {
         $registry->set("inviteMultiple", true);
     }
     return true;
 }