初始化仓库
This commit is contained in:
80
member/models/User.php
Normal file
80
member/models/User.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace member\models;
|
||||
|
||||
use Yii;
|
||||
use yii\web\IdentityInterface;
|
||||
|
||||
class User extends \common\models\User implements IdentityInterface
|
||||
{
|
||||
public static function findIdentity($id)
|
||||
{
|
||||
return static::findOne(['id' => $id]);
|
||||
}
|
||||
|
||||
public static function findIdentityByAccessToken($token, $type = null)
|
||||
{
|
||||
$pos = strrpos($token,'_');
|
||||
if(!$pos){
|
||||
return false;
|
||||
}
|
||||
$user = static::find()->where(['token' => $token])->one();
|
||||
if(!$user){
|
||||
return false;
|
||||
}
|
||||
$time = substr($token,$pos+1);
|
||||
if($time + 30*24*60*60 < time()){
|
||||
return false;
|
||||
}
|
||||
return $user;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user