mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/0.7.0/seo' into test
This commit is contained in:
commit
e05c839085
|
@ -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:
|
||||
|
|
43
docs/docs.go
43
docs/docs.go
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue