Skip to content

Commit

Permalink
Fix with frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Sep 9, 2024
1 parent 0f9413e commit 16db113
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cmd/web_server/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
}
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions cmd/web_server/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 16db113

Please sign in to comment.