3x-ui/web/controller/base.go

34 lines
602 B
Go
Raw Normal View History

2023-02-09 22:18:06 +03:00
package controller
import (
"net/http"
"x-ui/web/session"
"github.com/gin-gonic/gin"
2023-02-09 22:18:06 +03:00
)
type BaseController struct {
}
func (a *BaseController) checkLogin(c *gin.Context) {
if !session.IsLogin(c) {
if isAjax(c) {
2023-02-18 15:37:32 +03:00
pureJsonMsg(c, false, I18n(c, "pages.login.loginAgain"))
2023-02-09 22:18:06 +03:00
} else {
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
}
c.Abort()
} else {
c.Next()
}
}
2023-02-18 15:37:32 +03:00
func I18n(c *gin.Context, name string) string {
anyfunc, _ := c.Get("I18n")
i18n, _ := anyfunc.(func(key string, params ...string) (string, error))
2023-02-09 22:18:06 +03:00
2023-02-18 15:37:32 +03:00
message, _ := i18n(name)
2023-02-09 22:18:06 +03:00
2023-02-18 15:37:32 +03:00
return message
2023-02-09 22:18:06 +03:00
}