1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace common\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * Class AccessToken
- * @package common\models
- */
- class AccessToken extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::className(),
- 'createdAtAttribute' => 'created_at',
- 'updatedAtAttribute' => 'updated_at',
- //'value' => new Expression('NOW()'),
- 'value' => function() { return time();},
- ],
- ];
- }
- /**
- * getUidByApiToken
- * @param $token
- * @return bool
- */
- public static function getUidByApiToken($token)
- {
- $uid = static::find()->select('user_id')
- ->where(['access_token' => $token])
- ->andWhere(['>', 'expires', time()])
- ->scalar();
- return $uid != null && is_numeric($uid) ? $uid : null;
- }
- }
|