main.go 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package controller
  2. import (
  3. "git.wanbits.cc/sin/flytalk/models"
  4. "github.com/gin-gonic/gin"
  5. )
  6. //func ActionMain(w http.ResponseWriter, r *http.Request) {
  7. // sessionId := tools.GetCookie(r, "session_id")
  8. // info := AuthCheck(sessionId)
  9. // if len(info) == 0 {
  10. // http.Redirect(w, r, "/login", 302)
  11. // return
  12. // }
  13. // render := tmpl.NewRender(w)
  14. // render.Display("main", render)
  15. //}
  16. func MainCheckAuth(c *gin.Context) {
  17. id, _ := c.Get("kefu_id")
  18. userinfo := models.FindUserRole("user.avator,user.name,user.id, role.name role_name", id)
  19. c.JSON(200, gin.H{
  20. "code": 200,
  21. "msg": "验证成功",
  22. "result": gin.H{
  23. "avator": userinfo.Avator,
  24. "name": userinfo.Name,
  25. "role_name": userinfo.RoleName,
  26. },
  27. })
  28. }
  29. func GetStatistics(c *gin.Context) {
  30. visitors := models.CountVisitors()
  31. message := models.CountMessage()
  32. session := len(clientList)
  33. c.JSON(200, gin.H{
  34. "code": 200,
  35. "msg": "ok",
  36. "result": gin.H{
  37. "visitors": visitors,
  38. "message": message,
  39. "session": session,
  40. },
  41. })
  42. }