diff --git a/cmd/web_server/handler/auth.go b/cmd/web_server/handler/auth.go index 06703c4..ee20932 100644 --- a/cmd/web_server/handler/auth.go +++ b/cmd/web_server/handler/auth.go @@ -58,6 +58,7 @@ func githubCallback(ginCtx *gin.Context) { ls, err := user_service.StartLoginSession(ginCtx, user.Account) if err != nil { gin_utils.NewInternalError(ginCtx, fmt.Sprintf("failed to start login session: %v", err)) + return } middleware.SetLoginSessionKeyCookie(ginCtx, ls.Key) @@ -69,6 +70,7 @@ func loginGithub(ginCtx *gin.Context) { u, err := auth_module.GetGithubOauthEntryURL(callbackURL) if err != nil { gin_utils.NewInternalError(ginCtx, fmt.Sprintf("failed to get github oauth entry url: %v", err)) + return } ginCtx.Redirect(http.StatusFound, u.String()) } @@ -99,6 +101,7 @@ func loginByPassword(ginCtx *gin.Context) { user, err := user_model.GetUserByAccountPassword(db, body.Account, body.Password) if err != nil { gin_utils.NewUnauthorizedError(ginCtx, "account or password incorrect") + return } ls, err := user_service.StartLoginSession(ginCtx, user.Account) diff --git a/cmd/web_server/handler/user.go b/cmd/web_server/handler/user.go index a11baf1..469432c 100644 --- a/cmd/web_server/handler/user.go +++ b/cmd/web_server/handler/user.go @@ -19,9 +19,9 @@ func SetupUserRouter(baseRoute *gin.RouterGroup) { g.GET("", middleware.HandleRequireLogin, middleware.BuildCasbinEnforceHandlerWithDomain("system"), - GetUserList, + getUserList, ) - g.GET("/me", middleware.HandleRequireLogin, me) + g.GET("/current", middleware.HandleRequireLogin, getCurrentUser) g.POST("/:account/role", middleware.HandleRequireLogin, middleware.BuildCasbinEnforceHandlerWithDomain("system"), @@ -50,7 +50,7 @@ func AddUserCasbinPolicies() error { return nil } -func GetUserList(ginCtx *gin.Context) { +func getUserList(ginCtx *gin.Context) { limit, err := gin_utils.QueryInt(ginCtx, "limit", 10) if err != nil { gin_utils.NewInvalidParamError(ginCtx, "limit", err.Error()) @@ -85,7 +85,7 @@ func GetUserList(ginCtx *gin.Context) { // @Router /user/me [get] // @Success 200 // @Failure 401 -func me(ginCtx *gin.Context) { +func getCurrentUser(ginCtx *gin.Context) { ls, err := middleware.GetLoginSessionFromGinCtx(ginCtx) if err != nil { gin_utils.NewUnauthorizedError(ginCtx, "cannot load login session from cookie")