func IndexHandler(c *gin.Context) { var listTmpl = template.Must(template.ParseFiles("templates/base.html", "apps/message/templates/index.html")) User, _ := c.Get("User") Sid, _ := c.Get("Sid") sid := Sid.(string) //fmt.Println("User+++==>", Sid) bapi := auth.GetBackendApi2(c) data := gin.H{} if err := bapi.Get(&data, "http://127.0.0.1:8080/messages"); err != nil { fmt.Println("bapi failed:", err) return } if e, exist := data["error"]; exist { fmt.Println("get messages failed:", e.(string)) if e.(string) == "session expired" { conn := utils.OpenDB() auth.Signout_del_session(conn, sid) c.Redirect(302, "/auth/signin") return } // TODO: else } data["User"] = User if err := listTmpl.Execute(c.Writer, data); err != nil { fmt.Println(err.Error()) } }
func GetSession(c *gin.Context) (session *Session, err error) { db := utils.OpenDB() var u Userinfo cookie, err := c.Request.Cookie("Sid") fmt.Println("Sid-->", cookie) if err != nil { fmt.Println("hhhhhh--err", err) return nil, err } session = &Session{ Sid: cookie.Value, } u.get_userinfo(db, session.Sid) //fmt.Println("----->", (time.Now().UTC().Format("2006-01-02 15:04:05"))) if !u.Online { u.set_useronline(db, u.Id) } session.User = u return }