init
This commit is contained in:
commit
d12d6fa4b1
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace dominion\user;
|
||||
|
||||
use Yii;
|
||||
use yii\base\BaseObject;
|
||||
use yii\web\IdentityInterface;
|
||||
use yii\filters\RateLimitInterface;
|
||||
use \Lcobucci\JWT\Validation\Constraint\SignedWith;
|
||||
|
||||
class User extends BaseObject implements IdentityInterface , RateLimitInterface
|
||||
{
|
||||
public $id;
|
||||
public $username;
|
||||
public $password;
|
||||
public $authKey;
|
||||
public $accessToken;
|
||||
public $role;
|
||||
public $priceType = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function findIdentity($id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function findIdentityByAccessToken($token, $type = null)
|
||||
{
|
||||
return new static([
|
||||
'id' =>(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;
|
||||
}
|
||||
}
|
|
@ -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\\": ""
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue