2023-02-09 22:18:06 +03:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"x-ui/web/session"
|
2023-04-29 18:17:44 +03:00
|
|
|
|
|
|
|
"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
|
|
|
}
|