Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\models;
- use yii\db\Query;
- class User extends \yii\base\Object implements \yii\web\IdentityInterface
- {
- public $username;
- public $authKey;
- public $accessToken;
- public $UID;
- public $LOGIN;
- public $PASSWORD;
- public $EMAIL;
- public $GROUP;
- private static $users;
- /**
- * @inheritdoc
- */
- private function setProp(& $user){
- $user['authKey'] = $user['UID']."key";
- $user['accessToken'] = $user['UID']."token";
- $user['username'] = $user['LOGIN'];
- }
- private function setUsers() {
- $query = new Query();
- $query->select('*')->from('users');
- self::$users = $query->all();
- }
- public static function findIdentity($id)
- {
- self::setUsers();
- foreach (self::$users as $user) {
- if ($user['UID'] === $id) {
- self::setProp($user);
- return new static($user);
- }
- }
- return null;
- }
- /**
- * @inheritdoc
- */
- public static function findIdentityByAccessToken($token, $type = null)
- {
- self::setUsers();
- foreach (self::$users as $user) {
- if ($user['accessToken'] === $token) {
- self::setProp($user);
- return new static($user);
- }
- }
- return null;
- }
- /**
- * Finds user by username
- *
- * @param string $username
- * @return static|null
- */
- public static function findByUsername($username)
- {
- self::setUsers();
- foreach (self::$users as $user) {
- if (strcasecmp($user['LOGIN'], $username) === 0) {
- self::setProp($user);
- return new static($user);
- }
- }
- return null;
- }
- /**
- * @inheritdoc
- */
- public function getId()
- {
- return $this->UID;
- }
- /**
- * @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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement