diff --git a/gin_ops/routers/api_users.go b/gin_ops/routers/api_users.go index 4540779..231e67a 100644 --- a/gin_ops/routers/api_users.go +++ b/gin_ops/routers/api_users.go @@ -24,7 +24,7 @@ func user_logout(ctx *gin.Context) { //删除数据库里的cookie var cookie models.Cookie if err := mapstructure.Decode(cookie_any, &cookie); err == nil { - models.DB.Where(&cookie).Delete(&cookie) + models.DB.Where("ID=?", cookie.ID).Delete(&cookie) //删除前端cookie ctx.SetCookie("user", "", -1, "/", models.Configs_wed.Host, models.Configs_wed.Tls, true) ctx.Set("cookie", nil) @@ -71,7 +71,7 @@ func V1_user_api(r *gin.RouterGroup) { var user models.User user.Name = newUser.Name - if models.DB.Where(&user).First(&user).Error == nil { + if models.DB.Where("Name=?", user.Name).First(&user).Error == nil { //fmt.Println("找到用户:", user.ID) Return_json(ctx, "user_name_dup", nil) } else { @@ -121,7 +121,7 @@ func V1_user_api(r *gin.RouterGroup) { var user models.User user.Name = newUser.Name - if models.DB.Where(&user).First(&user).Error == nil { + if models.DB.Where("Name=?", user.Name).First(&user).Error == nil { // 有数据 //fmt.Println(user) //fmt.Println(newUser) @@ -163,7 +163,7 @@ func V1_user_api(r *gin.RouterGroup) { UserID: user.ID, } - models.DB.Where(&user_info).First(&user_info) + models.DB.Where("ID=?", user_info.ID).First(&user_info) red := map[string]interface{}{ "cookie": new_cookie, @@ -218,23 +218,26 @@ func V1_user_api(r *gin.RouterGroup) { Birthdate: models.Time_date_str_to_time(json_data.Birthday), } + sele := []string{"FirstName", "Username", "Birthdate"} + user_info := user_info_any.(*models.User_info) //先判断头像是否合法 if json_data.Avatar_id != 0 { file_info := models.File_info{} file_info.ID = json_data.Avatar_id - if models.DB.Where(&file_info).First(&file_info).Error == nil { + if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { //读取到文件,判断是不是图片 if file_info.Type == "image" && file_info.UserID == user_info.UserID { file_id_str := fmt.Sprintf("%d", file_info.ID) url_preview := path.Join(Url_flie_preview_from_id_head, file_id_str) updata_user_info.AvatarPath = url_preview + sele = append(sele, "AvatarPath") } } } - if models.DB.Where(&user_info).Select("FirstName", "Username", "Birthdate").Updates(&updata_user_info).Error == nil { + if models.DB.Where("ID=?", user_info.ID).Select(sele).Updates(&updata_user_info).Error == nil { Return_json(ctx, "api_ok", nil) } else { Return_json(ctx, "DB_err", nil) @@ -270,7 +273,7 @@ func V1_user_api(r *gin.RouterGroup) { user_fund := models.User{ ID: user_info.UserID, } - if models.DB.Where(&user_fund).Updates(&user_updata).Error == nil { + if models.DB.Where("ID=?", user_fund.ID).Updates(&user_updata).Error == nil { Return_json(ctx, "api_ok", nil) } else { Return_json(ctx, "DB_err", nil) @@ -304,12 +307,12 @@ func V1_user_api(r *gin.RouterGroup) { user_fund := models.User{ ID: user_info.UserID, } - models.DB.Where(&user_fund).First(&user_fund) + models.DB.Where("ID=?", user_fund.ID).First(&user_fund) if user_fund.Pass == pass_old { user_new := models.User{ Pass: pass_new, } - if models.DB.Where(&user_fund).Updates(&user_new).Error == nil { + if models.DB.Where("ID=?", user_fund.ID).Updates(&user_new).Error == nil { user_logout(ctx) //Return_json(ctx, "api_ok", nil) } else { diff --git a/gin_ops/routers/routers_api.go b/gin_ops/routers/routers_api.go index c19e4e3..18d4411 100644 --- a/gin_ops/routers/routers_api.go +++ b/gin_ops/routers/routers_api.go @@ -1,8 +1,6 @@ package routers import ( - "fmt" - "github.com/gin-gonic/gin" "github.com/mitchellh/mapstructure" ) @@ -24,7 +22,7 @@ func Router_api(r *gin.RouterGroup) { } if jsonData["data"] != nil { - fmt.Println(jsonData["data"]) + //fmt.Println(jsonData["data"]) var data_t map[string]interface{} if err = mapstructure.Decode(jsonData["data"], &data_t); err == nil { ctx.Set("data", &data_t) diff --git a/gin_ops/routers/routers_flie.go b/gin_ops/routers/routers_flie.go index 42aa51d..b1d5a55 100644 --- a/gin_ops/routers/routers_flie.go +++ b/gin_ops/routers/routers_flie.go @@ -28,7 +28,7 @@ func Router_file(r *gin.RouterGroup) { file_info := models.File_info{ ID: uint(id_int), } - if models.DB.Where(&file_info).First(&file_info).Error == nil { + if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { Return_file(ctx, &file_info, true) } else { //fmt.Println("not fund") @@ -53,7 +53,7 @@ func Router_file(r *gin.RouterGroup) { file_info := models.File_info{ ID: uint(id_int), } - if models.DB.Where(&file_info).First(&file_info).Error == nil { + if models.DB.Where("ID=?", file_info.ID).First(&file_info).Error == nil { Return_file(ctx, &file_info, false) } else { //fmt.Println("not fund") @@ -169,7 +169,7 @@ func Router_file(r *gin.RouterGroup) { if fund_file_info2.ID != 0 { //fmt.Println(fund_file_info2) fund_file_info2.Const += 1 - models.DB.Where(&fund_file_info).Updates(&fund_file_info2) + models.DB.Where("ID=?", fund_file_info.ID).Updates(&fund_file_info2) } else { fund_file_info.Path = dst models.DB.Create(&fund_file_info) // 传入指针 diff --git a/gin_ops/routers/uses.go b/gin_ops/routers/uses.go index faa73be..53dd47f 100644 --- a/gin_ops/routers/uses.go +++ b/gin_ops/routers/uses.go @@ -1,7 +1,6 @@ package routers import ( - "fmt" "saas/models" "time" @@ -13,7 +12,7 @@ func Use_login_from_cookie(ctx *gin.Context) { //先从缓存获取cookie值 cookie_value, is_have_cookie := ctx.Get("cookie_value") if is_have_cookie { - fmt.Println(cookie_value) + //fmt.Println(cookie_value) var cookie models.Cookie cookie.Value = cookie_value.(string)