|
5 | 5 | use Yii; |
6 | 6 | use yii\base\NotSupportedException; |
7 | 7 | use yii\behaviors\TimestampBehavior; |
8 | | -use yii\db\ActiveRecord; |
| 8 | +use base\db\ActiveRecord; |
9 | 9 | use yii\web\IdentityInterface; |
10 | 10 |
|
11 | 11 | /** |
|
17 | 17 | * @property string $password_reset_token |
18 | 18 | * @property string $email |
19 | 19 | * @property string $auth_key |
| 20 | + * @property string $access_token |
| 21 | + * @property string $refresh_token |
20 | 22 | * @property integer $status |
21 | 23 | * @property integer $created_at |
22 | 24 | * @property integer $updated_at |
| 25 | + * @property string $created_by |
| 26 | + * @property string $updated_by |
23 | 27 | * @property string $password write-only password |
24 | 28 | */ |
25 | 29 | class User extends ActiveRecord implements IdentityInterface |
@@ -49,7 +53,7 @@ public static function findIdentity($id) |
49 | 53 | */ |
50 | 54 | public static function findIdentityByAccessToken($token, $type = null) |
51 | 55 | { |
52 | | - throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); |
| 56 | + return static::findOne(['access_token' => $token, 'status' => self::STATUS_ACTIVE]); |
53 | 57 | } |
54 | 58 |
|
55 | 59 | /** |
@@ -187,4 +191,36 @@ public function removePasswordResetToken() |
187 | 191 | { |
188 | 192 | $this->password_reset_token = null; |
189 | 193 | } |
| 194 | + |
| 195 | + /** |
| 196 | + * Generates new access token |
| 197 | + */ |
| 198 | + public function generateAccessToken() |
| 199 | + { |
| 200 | + $this->access_token = Yii::$app->security->generateRandomString(32) . '_' . time(); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Removes access token |
| 205 | + */ |
| 206 | + public function removeAccessToken() |
| 207 | + { |
| 208 | + $this->access_token = null; |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * Generates new refresh token |
| 213 | + */ |
| 214 | + public function generateRefreshToken() |
| 215 | + { |
| 216 | + $this->refresh_token = Yii::$app->security->generateRandomString(32) . '_' . time(); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Removes access token |
| 221 | + */ |
| 222 | + public function removeRefreshToken() |
| 223 | + { |
| 224 | + $this->refresh_token = null; |
| 225 | + } |
190 | 226 | } |
0 commit comments