fix: 优化账号插件的用户模型初始化

This commit is contained in:
邹景立 2025-04-06 09:10:54 +08:00
parent 51d47113cb
commit 948185042d

View File

@ -161,6 +161,8 @@ class AccountAccess implements AccountInterface
} }
$this->bind = $this->save(array_merge($data, ['type' => $this->type])); $this->bind = $this->save(array_merge($data, ['type' => $this->type]));
if ($this->bind->isEmpty()) throw new Exception('更新资料失败!'); if ($this->bind->isEmpty()) throw new Exception('更新资料失败!');
// 刷新更新用户模型
$this->user = $this->bind->user()->findOrEmpty();
return $this->token()->get($rejwt); return $this->token()->get($rejwt);
} }
@ -178,6 +180,9 @@ class AccountAccess implements AccountInterface
} }
$data = $this->bind->hidden(['sort', 'password'], true)->toArray(); $data = $this->bind->hidden(['sort', 'password'], true)->toArray();
if ($this->bind->isExists()) { if ($this->bind->isExists()) {
if ($this->user->isEmpty()) {
$this->user = $this->bind->user()->findOrEmpty();
}
$data['user'] = $this->user->hidden(['sort', 'password'], true)->toArray(); $data['user'] = $this->user->hidden(['sort', 'password'], true)->toArray();
if ($rejwt) $data['token'] = $this->isjwt ? JwtExtend::token([ if ($rejwt) $data['token'] = $this->isjwt ? JwtExtend::token([
'type' => $this->auth->getAttr('type'), 'token' => $this->auth->getAttr('token') 'type' => $this->auth->getAttr('type'), 'token' => $this->auth->getAttr('token')
@ -419,6 +424,7 @@ class AccountAccess implements AccountInterface
* @param boolean $expire * @param boolean $expire
* @return AccountInterface * @return AccountInterface
* @throws \think\admin\Exception * @throws \think\admin\Exception
* @throws \think\db\exception\DbException
*/ */
public function token(bool $expire = true): AccountInterface public function token(bool $expire = true): AccountInterface
{ {