feat: add dedicated change password api and fix token expire code

This commit is contained in:
2026-05-20 16:53:08 +08:00
parent 61d14d1b45
commit 60cb2b80cd
4 changed files with 83 additions and 12 deletions
@@ -57,12 +57,12 @@ class AssetAppController extends BaseApiController
{
$token = $this->request->header('token');
if (empty($token)) {
return $this->fail('请先登录', [], 401);
return $this->fail('请先登录', [], -1);
}
$userId = cache('asset_token_' . $token);
if (!$userId) {
return $this->fail('登录已过期', [], 401);
return $this->fail('登录已过期', [], -1);
}
$type = $this->request->get('type', 1); // 1:图片 2:视频 3:语音
@@ -95,4 +95,37 @@ class AssetAppController extends BaseApiController
'page_size' => $pageSize,
]);
}
/**
* @notes 修改密码
*/
public function changePassword()
{
$token = $this->request->header('token');
if (empty($token)) {
return $this->fail('请先登录', [], -1);
}
$userId = cache('asset_token_' . $token);
if (!$userId) {
return $this->fail('登录已过期', [], -1);
}
$oldPassword = $this->request->post('old_password');
$password = $this->request->post('password');
$user = AssetUser::find($userId);
if (!$user) {
return $this->fail('用户不存在', [], -1);
}
if (!password_verify($oldPassword, $user->password)) {
return $this->fail('原密码不正确');
}
$user->password = password_hash($password, PASSWORD_DEFAULT);
$user->save();
return $this->success('密码修改成功');
}
}