Auto reg user, event map

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-25 21:30:26 +08:00
parent c7cefb3898
commit b30d9db69d
10 changed files with 116 additions and 41 deletions

View File

@@ -1,8 +1,8 @@
package user
import (
"net/http"
"nixcn-cms/data"
"time"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
@@ -12,30 +12,35 @@ func Info(c *gin.Context) {
data := new(data.User)
userId, ok := c.Get("user_id")
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{
c.JSON(403, gin.H{
"status": "user not found",
})
return
}
err := data.GetByUserId(userId.(uuid.UUID))
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{
c.JSON(403, gin.H{
"status": "user not found",
})
return
}
var checkinTime any = nil
if !data.Checkin.IsZero() {
checkinTime = data.Checkin
// Set time nil if time is zero
for k, v := range data.Checkin {
if t, ok := v.(time.Time); ok && t.IsZero() {
data.Checkin[k] = nil
}
}
c.JSON(http.StatusOK, gin.H{
c.JSON(200, gin.H{
"user_id": data.UserId,
"email": data.Email,
"type": data.Type,
"nickname": data.Nickname,
"subtitle": data.Subtitle,
"avatar": data.Avatar,
"checkin": checkinTime,
"checkin": data.Checkin,
"joined_event": data.JoinedEvent,
"permission_level": data.PermissionLevel,
})
}