Use utils.HttpResponse/Abort to replace c.JSON/Abort
All checks were successful
Build Backend (NixCN CMS) TeamCity build finished
Build Frontend (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-06 12:49:55 +08:00
parent 70846e0d1e
commit 6a9c013799
14 changed files with 203 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package user
import (
"nixcn-cms/data"
"nixcn-cms/internal/cryptography"
"nixcn-cms/utils"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
@@ -12,12 +13,12 @@ func Update(c *gin.Context) {
// New user model
userIdOrig, ok := c.Get("user_id")
if !ok {
c.JSON(403, gin.H{"status": "userid error"})
utils.HttpResponse(c, 403, "", "userid error")
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
c.JSON(500, gin.H{"status": "failed to parse uuid"})
utils.HttpResponse(c, 500, "", "failed to parse uuid")
return
}
@@ -27,18 +28,29 @@ func Update(c *gin.Context) {
// Get user info
userData, err := new(data.User).GetByUserId(userId)
if err != nil {
c.JSON(500, gin.H{"status": "failed to find user"})
utils.HttpResponse(c, 500, "", "failed to find user")
return
}
userData.Avatar = ReqInfo.Avatar
if len(ReqInfo.Email) < 5 || len(ReqInfo.Email) >= 255 {
utils.HttpResponse(c, 400, "", "invilad email")
return
}
userData.Email = ReqInfo.Email
if len(ReqInfo.Username) < 5 || len(ReqInfo.Username) >= 255 {
utils.HttpResponse(c, 400, "", "invilad user name")
return
}
userData.Username = ReqInfo.Username
userData.Nickname = ReqInfo.Nickname
userData.Subtitle = ReqInfo.Subtitle
userData.Avatar = ReqInfo.Avatar
if ReqInfo.Bio != "" {
if !cryptography.IsBase64Std(ReqInfo.Bio) {
c.JSON(400, gin.H{"status": "invalid base64"})
utils.HttpResponse(c, 400, "", "invalid base64")
}
}
userData.Bio = ReqInfo.Bio
@@ -46,5 +58,5 @@ func Update(c *gin.Context) {
// Update user info
userData.UpdateByUserID(userId)
c.JSON(200, gin.H{"status": "success"})
utils.HttpResponse(c, 200, "", "success")
}