0055e1ab31
* 'feature' of https://github.com/mongosoft/yii2: returned back formatting language files code style. WHILE code style. FOR code style. FOREACH code style. operator IF @param, @var, @property and @return must declare types as boolean, integer, string, array or null short echo tags short array syntax Conflicts: extensions/apidoc/commands/RenderController.php extensions/apidoc/models/BaseDoc.php extensions/apidoc/models/Context.php extensions/apidoc/templates/bootstrap/Renderer.php extensions/apidoc/templates/bootstrap/layouts/guide.php extensions/apidoc/templates/bootstrap/layouts/main.php extensions/apidoc/templates/bootstrap/views/index.php extensions/apidoc/templates/html/Renderer.php extensions/apidoc/templates/offline/views/index.php extensions/apidoc/templates/offline/views/offline.php extensions/apidoc/templates/online/views/index.php extensions/elasticsearch/Connection.php extensions/redis/ActiveQuery.php framework/base/ErrorException.php framework/helpers/BaseFileHelper.php tests/unit/framework/helpers/FileHelperTest.php
102 lines
1.7 KiB
PHP
102 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\models;
|
|
|
|
class User extends \yii\base\Object implements \yii\web\IdentityInterface
|
|
{
|
|
public $id;
|
|
public $username;
|
|
public $password;
|
|
public $authKey;
|
|
public $accessToken;
|
|
|
|
private static $users = [
|
|
'100' => [
|
|
'id' => '100',
|
|
'username' => 'admin',
|
|
'password' => 'admin',
|
|
'authKey' => 'test100key',
|
|
'accessToken' => '100-token',
|
|
],
|
|
'101' => [
|
|
'id' => '101',
|
|
'username' => 'demo',
|
|
'password' => 'demo',
|
|
'authKey' => 'test101key',
|
|
'accessToken' => '101-token',
|
|
],
|
|
];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static function findIdentity($id)
|
|
{
|
|
return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public static function findIdentityByAccessToken($token)
|
|
{
|
|
foreach (self::$users as $user) {
|
|
if ($user['accessToken'] === $token) {
|
|
return new static($user);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Finds user by username
|
|
*
|
|
* @param string $username
|
|
* @return static|null
|
|
*/
|
|
public static function findByUsername($username)
|
|
{
|
|
foreach (self::$users as $user) {
|
|
if (strcasecmp($user['username'], $username) === 0) {
|
|
return new static($user);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getAuthKey()
|
|
{
|
|
return $this->authKey;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function validateAuthKey($authKey)
|
|
{
|
|
return $this->authKey === $authKey;
|
|
}
|
|
|
|
/**
|
|
* Validates password
|
|
*
|
|
* @param string $password password to validate
|
|
* @return boolean if password provided is valid for current user
|
|
*/
|
|
public function validatePassword($password)
|
|
{
|
|
return $this->password === $password;
|
|
}
|
|
}
|