fix(admin): 添加管理操作错误处理及更新模板样式
- 管理后台帖子与用户审核操作中添加失败错误重定向处理 - 管理后台帖子、用户、评论删除操作中添加错误检查及提示 - 用户角色更新操作失败时添加错误重定向 - 用户封禁通知失败时添加相应错误提示 - 登录登出时session保存加入错误处理 - 讨论区上传目录创建失败时显示错误提示 - 移除admin_dashboard.html多余样式及修正侧边栏当前页高亮 - admin_posts.html和admin_users.html添加状态样式动态使用的隐藏span元素 - admin_users.html为角色选择添加label以提升无障碍性 - 升级项目依赖版本,包含gin、gorm、validator等核心库版本更新
This commit is contained in:
@@ -8,9 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"lv8girl/internal/middleware"
|
||||
"lv8girl/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UserController struct {
|
||||
@@ -86,7 +87,10 @@ func (c *UserController) UploadAvatar(ctx *gin.Context) {
|
||||
uploadDir := "uploads/avatars"
|
||||
|
||||
if _, err := os.Stat(uploadDir); os.IsNotExist(err) {
|
||||
os.MkdirAll(uploadDir, 0755)
|
||||
if err := os.MkdirAll(uploadDir, 0755); err != nil {
|
||||
ctx.Redirect(http.StatusFound, "/profile?error=创建上传目录失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
imagePath := filepath.Join(uploadDir, filename)
|
||||
@@ -97,6 +101,9 @@ func (c *UserController) UploadAvatar(ctx *gin.Context) {
|
||||
|
||||
// 将路径转换为 URL 友好的格式(使用正斜杠)
|
||||
avatarPath := filepath.ToSlash(imagePath)
|
||||
c.userSvc.UpdateAvatar(userID, avatarPath)
|
||||
if err := c.userSvc.UpdateAvatar(userID, avatarPath); err != nil {
|
||||
ctx.Redirect(http.StatusFound, "/profile?error=头像更新失败")
|
||||
return
|
||||
}
|
||||
ctx.Redirect(http.StatusFound, "/profile?success=头像更新成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user