base.go 601 B

1234567891011121314151617181920212223242526272829303132
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. "x-ui/web/session"
  6. )
  7. type BaseController struct {
  8. }
  9. func (a *BaseController) checkLogin(c *gin.Context) {
  10. if !session.IsLogin(c) {
  11. if isAjax(c) {
  12. pureJsonMsg(c, false, I18n(c, "pages.login.loginAgain"))
  13. } else {
  14. c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
  15. }
  16. c.Abort()
  17. } else {
  18. c.Next()
  19. }
  20. }
  21. func I18n(c *gin.Context, name string) string {
  22. anyfunc, _ := c.Get("I18n")
  23. i18n, _ := anyfunc.(func(key string, params ...string) (string, error))
  24. message, _ := i18n(name)
  25. return message
  26. }