Files
xk-api-yii/service/models/ServiceUser.php

82 lines
1.9 KiB
PHP
Raw Normal View History

2024-09-19 11:32:39 +08:00
<?php
namespace service\models;
use Yii;
2024-12-19 19:20:27 +08:00
use yii\web\IdentityInterface;
2024-09-19 11:32:39 +08:00
2024-12-19 19:20:27 +08:00
class ServiceUser extends \common\models\oldDb\ServiceUser implements IdentityInterface
2024-09-19 11:32:39 +08:00
{
public static $token = null;//记录下当前token,方便退出
public static function findIdentity($id)
{
return static::findOne(['id' => $id]);
}
public static function findIdentityByAccessToken($token, $type = null)
{
2024-12-19 19:20:27 +08:00
$checkToken = \common\models\oldDb\ServiceUserToken::checkToken($token);
2024-09-19 11:32:39 +08:00
if(!$checkToken){
return false;
}
$su_id = $checkToken->su_id;
$su = static::findOne($su_id);
if(!$su_id || !$su || $su->is_delete){
return false;
}
self::$token = $token;
return $su;
}
/**
* 验证密码
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password);
}
/**
* 设置加密后的密码
*
* @param string $password
*/
public function setPassword($password)
{
$this->password = Yii::$app->security->generatePasswordHash($password);
}
public function getId()
{
return $this->id;
}
/**
* ---------------------------------------
* 获取密码干扰字符串
* @return string
* ---------------------------------------
*/
public function getAuthKey()
{
return $this->salt;
}
/**
* ---------------------------------------
* 验证
* @param string $authKey
* @return bool
* ---------------------------------------
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
}