mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 21:24:10 +00:00
Add a simplified dashboard page for non-admin users showing username, traffic usage, expiry time, and logout button. Implement role-based routing so user-role accounts are redirected to their own dashboard instead of the admin panel. Add getUserInfo API endpoint and i18n translations across all 13 supported locales.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/mhsanaei/3x-ui/v2/web/session"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// XUIController is the main controller for the X-UI panel, managing sub-controllers.
|
|
type XUIController struct {
|
|
BaseController
|
|
|
|
settingController *SettingController
|
|
xraySettingController *XraySettingController
|
|
}
|
|
|
|
// NewXUIController creates a new XUIController and initializes its routes.
|
|
func NewXUIController(g *gin.RouterGroup) *XUIController {
|
|
a := &XUIController{}
|
|
a.initRouter(g)
|
|
return a
|
|
}
|
|
|
|
// initRouter sets up the main panel routes and initializes sub-controllers.
|
|
func (a *XUIController) initRouter(g *gin.RouterGroup) {
|
|
g = g.Group("/panel")
|
|
g.Use(a.checkLogin)
|
|
|
|
g.GET("/", a.index)
|
|
g.GET("/user", a.user)
|
|
g.GET("/inbounds", a.inbounds)
|
|
g.GET("/settings", a.settings)
|
|
g.GET("/xray", a.xraySettings)
|
|
|
|
a.settingController = NewSettingController(g)
|
|
a.xraySettingController = NewXraySettingController(g)
|
|
}
|
|
|
|
// index renders the main panel index page. Non-admin users are redirected to the user dashboard.
|
|
func (a *XUIController) index(c *gin.Context) {
|
|
user := session.GetLoginUser(c)
|
|
if user.Role != "admin" {
|
|
c.Redirect(http.StatusTemporaryRedirect, "user")
|
|
return
|
|
}
|
|
html(c, "index.html", "pages.index.title", nil)
|
|
}
|
|
|
|
// user renders the user dashboard page.
|
|
func (a *XUIController) user(c *gin.Context) {
|
|
html(c, "user.html", "pages.user.title", nil)
|
|
}
|
|
|
|
// inbounds renders the inbounds management page.
|
|
func (a *XUIController) inbounds(c *gin.Context) {
|
|
html(c, "inbounds.html", "pages.inbounds.title", nil)
|
|
}
|
|
|
|
// settings renders the settings management page.
|
|
func (a *XUIController) settings(c *gin.Context) {
|
|
html(c, "settings.html", "pages.settings.title", nil)
|
|
}
|
|
|
|
// xraySettings renders the Xray settings page.
|
|
func (a *XUIController) xraySettings(c *gin.Context) {
|
|
html(c, "xray.html", "pages.xray.title", nil)
|
|
}
|