コード例 #1
0
ファイル: WebUser.php プロジェクト: azamath/yii-account
 /**
  * @inheritDoc
  */
 public function init()
 {
     parent::init();
     if (!$this->isGuest) {
         // Note that saveAttributes can return false if the account is active twice the same second
         // because no attributes are updated, therefore we cannot throw an exception if save fails.
         $this->loadAccount()->saveAttributes(array('lastActiveAt' => Helper::sqlNow()));
     }
 }
コード例 #2
0
 /**
  * Returns whether the password for a specific account has expired.
  *
  * @param int $accountId account id.
  * @throws \nordsoftware\yii_account\exceptions\Exception if no password history model can be found.
  * @return bool whether the password has expired.
  */
 public function hasPasswordExpired($accountId)
 {
     $module = Helper::getModule();
     if ($module->passwordExpireTime === 0) {
         return false;
     }
     $criteria = new \CDbCriteria();
     $criteria->addCondition('accountId=:accountId');
     $criteria->params[':accountId'] = $accountId;
     $criteria->order = 'createdAt DESC';
     $modelClass = Helper::getModule()->getClassName(Module::CLASS_PASSWORD_HISTORY);
     /** @var \nordsoftware\yii_account\models\ar\AccountPasswordHistory $model */
     $model = \CActiveRecord::model($modelClass)->find($criteria);
     if ($model === null) {
         throw new Exception('Failed to check if password has expired.');
     }
     return strtotime(Helper::sqlNow()) - strtotime($model->createdAt) > $module->passwordExpireTime;
 }
コード例 #3
0
ファイル: Module.php プロジェクト: nordsoftware/yii-account
 /**
  * Returns whether the given token has expired.
  *
  * @param \CActiveRecord|\nordsoftware\yii_account\models\ar\AccountToken $tokenModel authentication token model.
  * @param int $expireTime number of seconds that the token is valid.
  * @return bool whether the token has expired.
  */
 public function hasTokenExpired(\CActiveRecord $tokenModel, $expireTime)
 {
     return strtotime(Helper::sqlNow()) - strtotime($tokenModel->createdAt) > $expireTime;
 }