Merge branch 'feat/0.7.0/seo' into test

This commit is contained in:
aichy126 2022-12-18 00:15:00 +08:00
commit e05c839085
9 changed files with 195 additions and 33 deletions

View File

@ -40,37 +40,30 @@ builds:
- linux
goarch:
- arm64
# - id: darwin
# main: ./cmd/answer/.
# binary: answer
# goos:
# - darwin
# ldflags: -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}} -X main.Time={{.Date}} -X main.BuildUser=goreleaser
#todo
# - id: darwin-arm64
# main: ./cmd/answer/.
# binary: answer
# env:
# - CC=oa64-clang
# - CXX=oa64-clang++
# goos:
# - darwin
# goarch:
# - arm64
# ldflags: -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}} -X main.Time={{.Date}} -X main.BuildUser=goreleaser
# flags: -v
# - id: darwin-amd64
# main: ./cmd/answer/.
# binary: answer
# env:
# - CC=o64-clang
# - CXX=o64-clang++
# goos:
# - darwin
# goarch:
# - amd64
# ldflags: -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}} -X main.Time={{.Date}} -X main.BuildUser=goreleaser
# flags: -v
- id: build-darwin-arm64
main: ./cmd/answer/.
binary: answer
env:
- CC=oa64-clang
- CXX=oa64-clang++
goos:
- darwin
goarch:
- arm64
ldflags: -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}} -X main.Time={{.Date}} -X main.BuildUser=goreleaser
flags: -v
- id: build-darwin-amd64
main: ./cmd/answer/.
binary: answer
env:
- CC=o64-clang
- CXX=o64-clang++
goos:
- darwin
goarch:
- amd64
ldflags: -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}} -X main.Time={{.Date}} -X main.BuildUser=goreleaser
flags: -v
archives:

View File

@ -4717,6 +4717,41 @@ const docTemplate = `{
}
}
},
"/answer/api/v1/user/register/captcha": {
"get": {
"description": "UserRegisterCaptcha",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"User"
],
"summary": "UserRegisterCaptcha",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.GetUserResp"
}
}
}
]
}
}
}
}
},
"/answer/api/v1/user/register/email": {
"post": {
"description": "UserRegisterByEmail",
@ -7725,6 +7760,14 @@ const docTemplate = `{
"pass"
],
"properties": {
"captcha_code": {
"description": "captcha_code",
"type": "string"
},
"captcha_id": {
"description": "captcha_id",
"type": "string"
},
"e_mail": {
"description": "email",
"type": "string",

View File

@ -4705,6 +4705,41 @@
}
}
},
"/answer/api/v1/user/register/captcha": {
"get": {
"description": "UserRegisterCaptcha",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"User"
],
"summary": "UserRegisterCaptcha",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/schema.GetUserResp"
}
}
}
]
}
}
}
}
},
"/answer/api/v1/user/register/email": {
"post": {
"description": "UserRegisterByEmail",
@ -7713,6 +7748,14 @@
"pass"
],
"properties": {
"captcha_code": {
"description": "captcha_code",
"type": "string"
},
"captcha_id": {
"description": "captcha_id",
"type": "string"
},
"e_mail": {
"description": "email",
"type": "string",

View File

@ -1823,6 +1823,12 @@ definitions:
type: object
schema.UserRegisterReq:
properties:
captcha_code:
description: captcha_code
type: string
captcha_id:
description: captcha_id
type: string
e_mail:
description: email
maxLength: 500
@ -4737,6 +4743,26 @@ paths:
summary: get user ranking
tags:
- User
/answer/api/v1/user/register/captcha:
get:
consumes:
- application/json
description: UserRegisterCaptcha
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/handler.RespBody'
- properties:
data:
$ref: '#/definitions/schema.GetUserResp'
type: object
summary: UserRegisterCaptcha
tags:
- User
/answer/api/v1/user/register/email:
post:
consumes:

View File

@ -232,6 +232,15 @@ func (uc *UserController) UserRegisterByEmail(ctx *gin.Context) {
return
}
req.IP = ctx.ClientIP()
captchaPass := uc.actionService.UserRegisterVerifyCaptcha(ctx, req.CaptchaID, req.CaptchaCode)
if !captchaPass {
errFields := append([]*validator.FormErrorField{}, &validator.FormErrorField{
ErrorField: "captcha_code",
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLang(ctx), reason.CaptchaVerificationFailed),
})
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), errFields)
return
}
resp, err := uc.userService.UserRegisterByEmail(ctx, req)
handler.HandleResponse(ctx, err, resp)
@ -412,6 +421,19 @@ func (uc *UserController) ActionRecord(ctx *gin.Context) {
handler.HandleResponse(ctx, err, resp)
}
// UserRegisterCaptcha godoc
// @Summary UserRegisterCaptcha
// @Description UserRegisterCaptcha
// @Tags User
// @Accept json
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.GetUserResp}
// @Router /answer/api/v1/user/register/captcha [get]
func (uc *UserController) UserRegisterCaptcha(ctx *gin.Context) {
resp, err := uc.actionService.UserRegisterCaptcha(ctx)
handler.HandleResponse(ctx, err, resp)
}
// UserNoticeSet godoc
// @Summary UserNoticeSet
// @Description UserNoticeSet

View File

@ -99,6 +99,7 @@ func (a *AnswerAPIRouter) RegisterMustUnAuthAnswerAPIRouter(r *gin.RouterGroup)
// user
r.POST("/user/login/email", a.userController.UserEmailLogin)
r.POST("/user/register/email", a.userController.UserRegisterByEmail)
r.GET("/user/register/captcha", a.userController.UserRegisterCaptcha)
r.POST("/user/email/verification", a.userController.UserVerifyEmail)
r.PUT("/user/email", a.userController.UserChangeEmailVerify)
r.GET("/user/action/record", a.userController.ActionRecord)

View File

@ -232,8 +232,10 @@ type UserRegisterReq struct {
// email
Email string `validate:"required,email,gt=0,lte=500" json:"e_mail" `
// password
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
IP string `json:"-" `
Pass string `validate:"required,gte=8,lte=32" json:"pass"`
IP string `json:"-" `
CaptchaID string `json:"captcha_id"` // captcha_id
CaptchaCode string `json:"captcha_code"` // captcha_code
}
func (u *UserRegisterReq) Check() (errFields []*validator.FormErrorField, err error) {

View File

@ -48,6 +48,26 @@ func (cs *CaptchaService) ActionRecord(ctx context.Context, req *schema.ActionRe
return
}
func (cs *CaptchaService) UserRegisterCaptcha(ctx context.Context) (resp *schema.ActionRecordResp, err error) {
resp = &schema.ActionRecordResp{}
resp.CaptchaID, resp.CaptchaImg, err = cs.GenerateCaptcha(ctx)
resp.Verify = true
return
}
func (cs *CaptchaService) UserRegisterVerifyCaptcha(
ctx context.Context, id string, VerifyValue string,
) bool {
if id == "" || VerifyValue == "" {
return false
}
pass, err := cs.VerifyCaptcha(ctx, id, VerifyValue)
if err != nil {
return false
}
return pass
}
// ActionRecordVerifyCaptcha
// Verify that you need to enter a CAPTCHA, and that the CAPTCHA is correct
func (cs *CaptchaService) ActionRecordVerifyCaptcha(
@ -58,6 +78,9 @@ func (cs *CaptchaService) ActionRecordVerifyCaptcha(
return true
}
if num >= 3 {
if id == "" || VerifyValue == "" {
return false
}
pass, err := cs.VerifyCaptcha(ctx, id, VerifyValue)
if err != nil {
return false

9
script/build_binary.sh Normal file
View File

@ -0,0 +1,9 @@
docker run \
--rm \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/github.com/answerdev/answer \
-v `pwd`/sysroot:/sysroot \
-w /go/src/github.com/answerdev/answer \
goreleaser/goreleaser-cross \
--rm-dist --skip-validate --skip-publish