Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update CheckPrivateMode

aichy126ee72b7e0b117
diff --git a/internal/base/middleware/auth.go b/internal/base/middleware/auth.go
index 24caa0e3..c53a1151 100644
--- a/internal/base/middleware/auth.go
+++ b/internal/base/middleware/auth.go
@@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/role"
"github.com/answerdev/answer/internal/service/siteinfo_common"
+ "github.com/answerdev/answer/ui"
"github.com/gin-gonic/gin"
"github.com/answerdev/answer/internal/base/handler"
@@ -15,6 +16,7 @@ import (
"github.com/answerdev/answer/internal/service/auth"
"github.com/answerdev/answer/pkg/converter"
"github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
)
var ctxUUIDKey = "ctxUuidKey"
@@ -143,25 +145,31 @@ func (am *AuthUserMiddleware) AdminAuth() gin.HandlerFunc {
func (am *AuthUserMiddleware) CheckPrivateMode() gin.HandlerFunc {
return func(ctx *gin.Context) {
- userLoginUrl := "/users/login"
- if ctx.Request.URL.Path == userLoginUrl {
- ctx.Next()
- return
- }
resp, err := am.siteInfoCommonService.GetSiteLogin(ctx)
if err != nil {
- ctx.Redirect(http.StatusTemporaryRedirect, userLoginUrl)
+ ShowIndexPage(ctx)
ctx.Abort()
return
}
if resp.LoginRequired {
- ctx.Redirect(http.StatusTemporaryRedirect, userLoginUrl)
+ ShowIndexPage(ctx)
ctx.Abort()
return
}
ctx.Next()
}
}
+func ShowIndexPage(ctx *gin.Context) {
+ ctx.Header("content-type", "text/html;charset=utf-8")
+ ctx.Header("X-Frame-Options", "DENY")
+ file, err := ui.Build.ReadFile("build/index.html")
+ if err != nil {
+ log.Error(err)
+ ctx.Status(http.StatusNotFound)
+ return
+ }
+ ctx.String(http.StatusOK, string(file))
+}
// GetLoginUserIDFromContext get user id from context
func GetLoginUserIDFromContext(ctx *gin.Context) (userID string) {
diff --git a/pkg/uid/sid_test.go b/pkg/uid/sid_test.go
index 3c8ab899..e91cd0dc 100644
--- a/pkg/uid/sid_test.go
+++ b/pkg/uid/sid_test.go
@@ -48,6 +48,6 @@ func Test_Demo(t *testing.T) {
// https://answer.dev.segmentfault.com/questions/D112
func Test_DeCode(t *testing.T) {
- aaa := DeShortID("D112")
+ aaa := DeShortID("D1w2")
spew.Dump(aaa)
}