rest api WIP

This commit is contained in:
Qiang Xue 2014-03-01 23:14:16 -05:00
parent be3c8c5e80
commit e9148837ee

View File

@ -8,6 +8,7 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
public $username; public $username;
public $password; public $password;
public $authKey; public $authKey;
public $apiKey;
private static $users = [ private static $users = [
'100' => [ '100' => [
@ -15,12 +16,14 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
'username' => 'admin', 'username' => 'admin',
'password' => 'admin', 'password' => 'admin',
'authKey' => 'test100key', 'authKey' => 'test100key',
'apiKey' => '100-apikey',
], ],
'101' => [ '101' => [
'id' => '101', 'id' => '101',
'username' => 'demo', 'username' => 'demo',
'password' => 'demo', 'password' => 'demo',
'authKey' => 'test101key', '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; 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 * Finds user by username
* *