This commit is contained in:
2025-07-02 19:42:16 +08:00
parent a6e4d6e219
commit 93d46459f9
10 changed files with 192 additions and 109 deletions
+7 -30
View File
@@ -5,40 +5,17 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/mitchellh/mapstructure"
)
func Fitst_use(ctx *gin.Context) {
cookie_vel := ""
//读取用户cookie,判断用户是否已登录
cookie_s, is_have_cookie := ctx.Cookie("user")
if is_have_cookie == nil {
cookie_vel = cookie_s
}
// 从cookie登录用户
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)
//转换传进来的数据
var jsonData map[string]interface{}
if err := ctx.ShouldBindJSON(&jsonData); err == nil {
//分离数据
var cookie_t models.Cookie
if err = mapstructure.Decode(jsonData["cookie"], &cookie_t); err == nil {
if cookie_t.Value != "" {
cookie_vel = cookie_t.Value
}
}
var data_t map[string]interface{}
if err = mapstructure.Decode(jsonData["data"], &data_t); err == nil {
ctx.Set("data", &data_t)
}
}
//fmt.Println(cookie_vel)
if cookie_vel != "" {
var cookie models.Cookie
cookie.Value = cookie_vel
cookie.Value = cookie_value.(string)
if models.DB.Where(&cookie).First(&cookie).Error == nil {
// 有数据