Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
commit6ced549deaecb42b9bb93ea9efcb4c1bbaabe8a4 (patch)
tree28d8d82530476cf607e4d05ca189ae05868711e6 /web/controller/index.go
parentf60682a6b7cb749fee403c84e2587c3ad7e7ced0 (diff)
docs: add comments for all functions
Diffstat (limited to 'web/controller/index.go')
-rw-r--r--web/controller/index.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/web/controller/index.go b/web/controller/index.go
index f21e3128..89de710b 100644
--- a/web/controller/index.go
+++ b/web/controller/index.go
@@ -13,12 +13,14 @@ import (
"github.com/gin-gonic/gin"
)
+// LoginForm represents the login request structure.
type LoginForm struct {
Username string `json:"username" form:"username"`
Password string `json:"password" form:"password"`
TwoFactorCode string `json:"twoFactorCode" form:"twoFactorCode"`
}
+// IndexController handles the main index and login-related routes.
type IndexController struct {
BaseController
@@ -27,12 +29,14 @@ type IndexController struct {
tgbot service.Tgbot
}
+// NewIndexController creates a new IndexController and initializes its routes.
func NewIndexController(g *gin.RouterGroup) *IndexController {
a := &IndexController{}
a.initRouter(g)
return a
}
+// initRouter sets up the routes for index, login, logout, and two-factor authentication.
func (a *IndexController) initRouter(g *gin.RouterGroup) {
g.GET("/", a.index)
g.POST("/login", a.login)
@@ -40,6 +44,7 @@ func (a *IndexController) initRouter(g *gin.RouterGroup) {
g.POST("/getTwoFactorEnable", a.getTwoFactorEnable)
}
+// index handles the root route, redirecting logged-in users to the panel or showing the login page.
func (a *IndexController) index(c *gin.Context) {
if session.IsLogin(c) {
c.Redirect(http.StatusTemporaryRedirect, "panel/")
@@ -48,6 +53,7 @@ func (a *IndexController) index(c *gin.Context) {
html(c, "login.html", "pages.login.title", nil)
}
+// login handles user authentication and session creation.
func (a *IndexController) login(c *gin.Context) {
var form LoginForm
@@ -95,6 +101,7 @@ func (a *IndexController) login(c *gin.Context) {
jsonMsg(c, I18nWeb(c, "pages.login.toasts.successLogin"), nil)
}
+// logout handles user logout by clearing the session and redirecting to the login page.
func (a *IndexController) logout(c *gin.Context) {
user := session.GetLoginUser(c)
if user != nil {
@@ -107,6 +114,7 @@ func (a *IndexController) logout(c *gin.Context) {
c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path"))
}
+// getTwoFactorEnable retrieves the current status of two-factor authentication.
func (a *IndexController) getTwoFactorEnable(c *gin.Context) {
status, err := a.settingService.GetTwoFactorEnable()
if err == nil {