From d12d6fa4b1fbda6704ed46d4c5cbbfb1936b0f99 Mon Sep 17 00:00:00 2001 From: Sasha Rybkin Date: Wed, 20 Nov 2024 16:00:38 +0300 Subject: [PATCH] init --- User.php | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 21 +++++++++ 2 files changed, 139 insertions(+) create mode 100644 User.php create mode 100644 composer.json diff --git a/User.php b/User.php new file mode 100644 index 0000000..7f9fe83 --- /dev/null +++ b/User.php @@ -0,0 +1,118 @@ +(string)$token->claims()->get('uid'), + 'role' =>(string)$token->claims()->get('role'), + 'priceType' => (int)$token->claims()->get('priceType'), + ]); + } + + /** + * Finds user by username + * + * @param string $username + * @return static|null + */ + public static function findByUsername($username) + { + return self::findIdentity((string) $username); + } + + /** + * {@inheritdoc} + */ + public function getId() + { + return $this->id; + } + + public function getRole() + { + return $this->role; + } + + /** + * {@inheritdoc} + */ + public function getAuthKey() + { + return null; + } + + /** + * {@inheritdoc} + */ + public function validateAuthKey($authKey) + { + return false; + } + + /** + * 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 === hash('sha512',$password); + } + + public function getRateLimit($request, $action) + { + return [1000, 1]; // $rateLimit requests per second +} + + public function loadAllowance($request, $action) + { + return [1000, time()]; +} + + public function saveAllowance($request, $action, $allowance, $timestamp) + { + + } + + public static function getPriceTypeId() + { + return isset(Yii::$app->user) ? Yii::$app->user->identity->priceType : 1; + } + + public static function getAuthMemberId() + { + return isset(Yii::$app->user) ? Yii::$app->user->identity->id : 0; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..de64ca2 --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "dominion/user", + "description": "Функционал для работы с user", + "type": "yii2-extension", + "keywords": ["yii2","extension"], + "license": "MIT", + "authors": [ + { + "name": "Rybkin Sasha", + "email": "ribkin@dominion.ru" + } + ], + "require": { + "yiisoft/yii2": "~2.0.0" + }, + "autoload": { + "psr-4": { + "dominion\\user\\": "" + } + } +} \ No newline at end of file