diff --git a/models/User.php b/models/User.php index b890e69..8d008a8 100644 --- a/models/User.php +++ b/models/User.php @@ -8,6 +8,7 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface public $username; public $password; public $authKey; + public $apiKey; private static $users = [ '100' => [ @@ -15,12 +16,14 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface 'username' => 'admin', 'password' => 'admin', 'authKey' => 'test100key', + 'apiKey' => '100-apikey', ], '101' => [ 'id' => '101', 'username' => 'demo', 'password' => 'demo', 'authKey' => 'test101key', + 'apiKey' => '101-apikey', ], ]; @@ -32,6 +35,19 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface return isset(self::$users[$id]) ? new static(self::$users[$id]) : null; } + /** + * @inheritdoc + */ + public static function findIdentityByToken($token) + { + foreach (self::$users as $user) { + if ($user['apiKey'] === $token) { + return new static($user); + } + } + return null; + } + /** * Finds user by username *