修复一些问题

This commit is contained in:
2025-07-15 18:50:07 +08:00
parent fb3b205228
commit ec1deec155
5 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ func main() {
r.Static("/dist/", "./static/dist/") r.Static("/dist/", "./static/dist/")
//静态用户上传的文件 //静态用户上传的文件
r.Static("/avatar/", models.Configs_file.Pahts["avatar"]) //r.Static("/avatar/", models.Configs_file.Pahts["avatar"])
//store := cookie.NewStore([]byte("secret")) //store := cookie.NewStore([]byte("secret"))
// 自定义 404 页面(需要提前加载模板) // 自定义 404 页面(需要提前加载模板)
+1 -1
View File
@@ -60,7 +60,7 @@ type Cookie struct {
Path string `gorm:"size:255;not null;default:/"` Path string `gorm:"size:255;not null;default:/"`
ExpiresAt time.Time `gorm:"type:datetime;index"` ExpiresAt time.Time `gorm:"type:datetime;index"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP"` CreatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:CURRENT_TIMESTAMP"` UpdatedAt time.Time `gorm:"type:datetime;index;not null;default:CURRENT_TIMESTAMP"`
SecureFlag bool `gorm:"not null;default:false"` SecureFlag bool `gorm:"not null;default:false"`
HttpOnly bool `gorm:"not null;default:false"` HttpOnly bool `gorm:"not null;default:false"`
SameSite string `gorm:"size:10;not null;default:'Lax'"` SameSite string `gorm:"size:10;not null;default:'Lax'"`
+8 -8
View File
@@ -24,7 +24,7 @@ func user_logout(ctx *gin.Context) {
//删除数据库里的cookie //删除数据库里的cookie
var cookie models.Cookie var cookie models.Cookie
if err := mapstructure.Decode(cookie_any, &cookie); err == nil { if err := mapstructure.Decode(cookie_any, &cookie); err == nil {
models.DB.Where("ID=?", cookie.ID).Delete(&cookie) models.DB.Where(&cookie).Delete(&cookie)
//删除前端cookie //删除前端cookie
ctx.SetCookie("user", "", -1, "/", models.Configs_wed.Host, models.Configs_wed.Tls, true) ctx.SetCookie("user", "", -1, "/", models.Configs_wed.Host, models.Configs_wed.Tls, true)
ctx.Set("cookie", nil) ctx.Set("cookie", nil)
@@ -71,7 +71,7 @@ func V1_user_api(r *gin.RouterGroup) {
var user models.User var user models.User
user.Name = newUser.Name user.Name = newUser.Name
if models.DB.Where("Name=?", user.Name).First(&user).Error == nil { if models.DB.Where(&user).First(&user).Error == nil {
//fmt.Println("找到用户:", user.ID) //fmt.Println("找到用户:", user.ID)
Return_json(ctx, "user_name_dup", nil) Return_json(ctx, "user_name_dup", nil)
} else { } else {
@@ -121,7 +121,7 @@ func V1_user_api(r *gin.RouterGroup) {
var user models.User var user models.User
user.Name = newUser.Name user.Name = newUser.Name
if models.DB.Where("Name=?", user.Name).First(&user).Error == nil { if models.DB.Where(&user).First(&user).Error == nil {
// 有数据 // 有数据
//fmt.Println(user) //fmt.Println(user)
//fmt.Println(newUser) //fmt.Println(newUser)
@@ -163,7 +163,7 @@ func V1_user_api(r *gin.RouterGroup) {
UserID: user.ID, UserID: user.ID,
} }
models.DB.Where("ID=?", user_info.ID).First(&user_info) models.DB.Where(&user_info).First(&user_info)
red := map[string]interface{}{ red := map[string]interface{}{
"cookie": new_cookie, "cookie": new_cookie,
@@ -225,7 +225,7 @@ func V1_user_api(r *gin.RouterGroup) {
if json_data.Avatar_id != 0 { if json_data.Avatar_id != 0 {
file_info := models.File_info{} file_info := models.File_info{}
file_info.ID = json_data.Avatar_id file_info.ID = json_data.Avatar_id
if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { if models.DB.Where(&file_info).First(&file_info).Error == nil {
//读取到文件,判断是不是图片 //读取到文件,判断是不是图片
if file_info.Type == "image" && file_info.UserID == user_info.UserID { if file_info.Type == "image" && file_info.UserID == user_info.UserID {
file_id_str := fmt.Sprintf("%d", file_info.ID) file_id_str := fmt.Sprintf("%d", file_info.ID)
@@ -273,7 +273,7 @@ func V1_user_api(r *gin.RouterGroup) {
user_fund := models.User{ user_fund := models.User{
ID: user_info.UserID, ID: user_info.UserID,
} }
if models.DB.Where("ID=?", user_fund.ID).Updates(&user_updata).Error == nil { if models.DB.Where(&user_fund).Updates(&user_updata).Error == nil {
Return_json(ctx, "api_ok", nil) Return_json(ctx, "api_ok", nil)
} else { } else {
Return_json(ctx, "DB_err", nil) Return_json(ctx, "DB_err", nil)
@@ -307,12 +307,12 @@ func V1_user_api(r *gin.RouterGroup) {
user_fund := models.User{ user_fund := models.User{
ID: user_info.UserID, ID: user_info.UserID,
} }
models.DB.Where("ID=?", user_fund.ID).First(&user_fund) models.DB.Where(&user_fund).First(&user_fund)
if user_fund.Pass == pass_old { if user_fund.Pass == pass_old {
user_new := models.User{ user_new := models.User{
Pass: pass_new, Pass: pass_new,
} }
if models.DB.Where("ID=?", user_fund.ID).Updates(&user_new).Error == nil { if models.DB.Where(&user_fund).Updates(&user_new).Error == nil {
user_logout(ctx) user_logout(ctx)
//Return_json(ctx, "api_ok", nil) //Return_json(ctx, "api_ok", nil)
} else { } else {
+2 -2
View File
@@ -28,7 +28,7 @@ func Router_file(r *gin.RouterGroup) {
file_info := models.File_info{ file_info := models.File_info{
ID: uint(id_int), ID: uint(id_int),
} }
if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { if models.DB.Where(&file_info).First(&file_info).Error == nil {
Return_file(ctx, &file_info, true) Return_file(ctx, &file_info, true)
} else { } else {
//fmt.Println("not fund") //fmt.Println("not fund")
@@ -53,7 +53,7 @@ func Router_file(r *gin.RouterGroup) {
file_info := models.File_info{ file_info := models.File_info{
ID: uint(id_int), ID: uint(id_int),
} }
if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { if models.DB.Where(&file_info).First(&file_info).Error == nil {
Return_file(ctx, &file_info, false) Return_file(ctx, &file_info, false)
} else { } else {
//fmt.Println("not fund") //fmt.Println("not fund")
+1 -1
View File
@@ -29,7 +29,7 @@ func Use_login_from_cookie(ctx *gin.Context) {
var cookie_up models.Cookie var cookie_up models.Cookie
cookie_up.UpdatedAt = time.Now() cookie_up.UpdatedAt = time.Now()
cookie_up.ExpiresAt = time.Now().Add(time.Duration(models.Configs_user.Cookie_timeout) * time.Second) //计算过期时间 cookie_up.ExpiresAt = time.Now().Add(time.Duration(models.Configs_user.Cookie_timeout) * time.Second) //计算过期时间
models.DB.Model(&models.Cookie{}).Where(&cookie).Updates(&cookie_up) models.DB.Where("ID=?", cookie.ID).Updates(&cookie_up)
//更新前端cookie //更新前端cookie
ctx.SetCookie("user", cookie.Value, models.Configs_user.Cookie_timeout, "/", models.Configs_wed.Host, models.Configs_wed.Tls, true) ctx.SetCookie("user", cookie.Value, models.Configs_user.Cookie_timeout, "/", models.Configs_wed.Host, models.Configs_wed.Tls, true)
cookie.UpdatedAt = cookie_up.UpdatedAt cookie.UpdatedAt = cookie_up.UpdatedAt