NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
### 用户认证 config/web.php指定模型, 该模型需要继承ActiveRecord 实现 yii\web\IdentityInterface 接口. 并且需要对里面的方法进行修改. ``` 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, //是否开启cookie ], ``` User类 : ``` <?php namespace app\models; use yii\db\ActiveRecord; use yii\web\IdentityInterface; class User extends ActiveRecord implements IdentityInterface { public $authKey; public function rules() { return [ [['username', 'password', 'email'], 'safe'] ]; } public static function findIdentity($id) { return static::findOne($id); } public static function findIdentityByAccessToken($token, $type = null) { return static::findOne(['access_token' => $token]); } public static function findByUsername($username) { } public function getId() { return $this->id; } public function getAuthKey() { return $this->authKey; } public function validateAuthKey($authKey) { return $this->authKey === $authKey; } public function validatePassword($password) { return $this->password === $password; } } ```