diff options
Diffstat (limited to 'web/controller/index.go')
| -rw-r--r-- | web/controller/index.go | 8 |
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 { |
