/**
  * Returns a new CcSubjsTokenQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return    CcSubjsTokenQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CcSubjsTokenQuery) {
         return $criteria;
     }
     $query = new CcSubjsTokenQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Beispiel #2
0
 public function checkToken($user_id, $token, $action)
 {
     $salt = md5("pro");
     $token_info = CcSubjsTokenQuery::create()->filterByDbAction($action)->filterByDbUserId($user_id)->filterByDbToken(sha1($token . $salt))->findOne();
     if (empty($token_info)) {
         return false;
     }
     $now = new DateTime();
     $token_life = new DateInterval(self::TOKEN_LIFETIME);
     $token_created = new DateTime($token_info->getDbCreated(), new DateTimeZone("UTC"));
     return $now->sub($token_life)->getTimestamp() < $token_created->getTimestamp();
 }
Beispiel #3
0
 /**
  * Returns the number of related CcSubjsToken objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related CcSubjsToken objects.
  * @throws     PropelException
  */
 public function countCcSubjsTokens(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCcSubjsTokens || null !== $criteria) {
         if ($this->isNew() && null === $this->collCcSubjsTokens) {
             return 0;
         } else {
             $query = CcSubjsTokenQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCcSubjs($this)->count($con);
         }
     } else {
         return count($this->collCcSubjsTokens);
     }
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CcSubjsTokenPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             CcSubjsTokenQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }