Merge branch 'feat/1.1.1/ai' into test

This commit is contained in:
aichy126 2023-07-14 16:26:14 +08:00
commit 51ab2a1bd8
4 changed files with 24 additions and 8 deletions

View File

@ -108,8 +108,12 @@ backend:
other: Manage tag synonyms
email:
other: Email
e_mail:
other: Email
password:
other: Password
pass:
other: Password
email_or_password_wrong_error:
other: Email and password do not match.
error:

View File

@ -107,8 +107,12 @@ backend:
other: 管理标签同义词
email:
other: 邮箱
e_mail:
other: 邮箱
password:
other: 密码
pass:
other: 密码
email_or_password_wrong_error:
other: 邮箱和密码不匹配。
error:

View File

@ -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) {

View File

@ -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)
}