Files
trihuy-russian/web/controller/base.go
T

38 lines
888 B
Go
Raw Normal View History

2023-02-09 22:48:06 +03:30
package controller
import (
"net/http"
2024-03-11 01:01:24 +03:30
2025-09-18 22:06:01 +02:00
"github.com/mhsanaei/3x-ui/logger"
"github.com/mhsanaei/3x-ui/web/locale"
"github.com/mhsanaei/3x-ui/web/session"
"github.com/gin-gonic/gin"
2023-02-09 22:48:06 +03:30
)
2024-03-11 01:01:24 +03:30
type BaseController struct{}
2023-02-09 22:48:06 +03:30
func (a *BaseController) checkLogin(c *gin.Context) {
if !session.IsLogin(c) {
if isAjax(c) {
2024-03-11 01:01:24 +03:30
pureJsonMsg(c, http.StatusUnauthorized, false, I18nWeb(c, "pages.login.loginAgain"))
2023-02-09 22:48:06 +03:30
} else {
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
}
c.Abort()
} else {
c.Next()
}
}
2023-05-21 03:29:27 +04:30
func I18nWeb(c *gin.Context, name string, params ...string) string {
2023-05-20 19:49:39 +04:30
anyfunc, funcExists := c.Get("I18n")
if !funcExists {
logger.Warning("I18n function not exists in gin context!")
return ""
}
i18nFunc, _ := anyfunc.(func(i18nType locale.I18nType, key string, keyParams ...string) string)
msg := i18nFunc(locale.Web, name, params...)
return msg
2023-02-09 22:48:06 +03:30
}