完成头像上传与更新

This commit is contained in:
2025-05-27 11:46:20 +08:00
parent b8d3757397
commit efa390294d
6 changed files with 239 additions and 240 deletions
+1 -1
View File
@@ -374,7 +374,7 @@ class IndexController extends BaseController
try {
// 验证上传的文件
validate([
'image' => 'filesize:51200|fileExt:jpg,png,gif,jpeg'
'image' => 'filesize:51200|fileExt:jpg,png,gif,jpeg,webp'
])->check($file);
// 存储文件到public磁盘的uploads目录
+12 -26
View File
@@ -140,34 +140,20 @@ class UserController extends BaseController
public function logout()
{
try {
// 记录退出日志
Log::record('用户退出登录', 'info');
// 1. 清除所有 session
// 清除所有会话和缓存数据
session(null);
// 2. 清除所有 cookie
// 正确的删除 cookie 方式
cookie('user_id', null, ['expire' => -1]);
cookie('user_account', null, ['expire' => -1]);
cookie('user_name', null, ['expire' => -1]);
cookie('user_avatar', null, ['expire' => -1]);
cookie('expire_time', null, ['expire' => -1]);
cookie('is_auto_login', null, ['expire' => -1]);
cookie('auto_login_attempted', null, ['expire' => -1]);
// 3. 清除缓存
Cache::tag('user_cache')->clear();
// 清除所有cookie
$cookies = ['user_id', 'user_account', 'user_name', 'user_avatar',
'expire_time', 'is_auto_login', 'auto_login_attempted', 'PHPSESSID'];
foreach ($cookies as $cookie) {
cookie($cookie, null, ['expire' => -1]);
}
// 4. 返回成功状态,并告诉前端清除 localStorage
return json([
'code' => 0,
'msg' => '退出成功',
'data' => [
'clear_storage' => true
]
]);
return json(['code' => 0, 'msg' => '退出成功', 'data' => ['clear_storage' => true]]);
} catch (\Exception $e) {
Log::record('退出登录失败:' . $e->getMessage(), 'error');
return json(['code' => 1, 'msg' => '退出失败:' . $e->getMessage()]);
@@ -395,8 +381,8 @@ class UserController extends BaseController
}
$ext = strtolower($file->getOriginalExtension());
if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
return json(['code' => 1, 'msg' => '只支持jpg、jpeg、png、gif格式的图片']);
if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) {
return json(['code' => 1, 'msg' => '只支持jpg、jpeg、png、gif、webp格式的图片']);
}
// 移动到指定目录