| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\models;
- class User extends \yii\base\Object implements \yii\web\IdentityInterface
- {
- public $id;
- public $username;
- public $password;
- public $authKey;
- private static $users = [
- '100' => [
- 'id' => '100',
- 'username' => 'admin',
- 'password' => 'admin',
- 'authKey' => 'test100key',
- ],
- '101' => [
- 'id' => '101',
- 'username' => 'demo',
- 'password' => 'demo',
- 'authKey' => 'test101key',
- ],
- ];
- /**
- * @inheritdoc
- */
- public static function findIdentity($id)
- {
- return isset(self::$users[$id]) ? new static(self::$users[$id]) : 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 bool if password provided is valid for current user
- */
- public function validatePassword($password)
- {
- return $this->password === $password;
- }
- }
|