diff --git a/apis/account.go b/apis/account.go index 1f5756f..dc39bfd 100644 --- a/apis/account.go +++ b/apis/account.go @@ -433,7 +433,7 @@ func ChangePassword(c *fiber.Ctx) error { func VerifyWithEmailOld(c *fiber.Ctx) error { email := c.Params("email") scope := c.Query("scope") - return verifyWithEmail(c, email, scope) + return verifyWithEmail(c, email, scope, false) } // VerifyWithEmail godoc @@ -445,6 +445,7 @@ func VerifyWithEmailOld(c *fiber.Ctx) error { // @Router /verify/email [get] // @Param email query string true "email" // @Param scope query string false "scope" +// @Param check query bool false "check" // @Success 200 {object} EmailVerifyResponse // @Failure 400 {object} common.MessageResponse // @Failure 403 {object} common.MessageResponse “email不在白名单中” @@ -452,10 +453,11 @@ func VerifyWithEmailOld(c *fiber.Ctx) error { func VerifyWithEmail(c *fiber.Ctx) error { email := c.Query("email") scope := c.Query("scope") - return verifyWithEmail(c, email, scope) + check := c.QueryBool("check") + return verifyWithEmail(c, email, scope, check) } -func verifyWithEmail(c *fiber.Ctx, email, givenScope string) error { +func verifyWithEmail(c *fiber.Ctx, email, givenScope string, check bool) error { if !utils.ValidateEmail(email) { return common.BadRequest("email invalid") } @@ -481,6 +483,19 @@ func verifyWithEmail(c *fiber.Ctx, email, givenScope string) error { } else { scope = "reset" } + + if check { + message := "该邮箱已注册" + if !registered { + message = "该邮箱未注册" + } + return c.JSON(EmailVerifyResponse{ + Message: message, + Registered: registered, + Scope: scope, + }) + } + if givenScope == "register" && scope == "reset" { return common.BadRequest("该用户已注册,请使用重置密码功能") } else if givenScope == "reset" && scope == "register" { @@ -513,8 +528,9 @@ func verifyWithEmail(c *fiber.Ctx, email, givenScope string) error { } return c.JSON(EmailVerifyResponse{ - Message: "验证邮件已发送,请查收\n如未收到,请检查邮件地址是否正确,检查垃圾箱,或重试", - Scope: scope, + Message: "验证邮件已发送,请查收\n如未收到,请检查邮件地址是否正确,检查垃圾箱,或重试", + Registered: registered, + Scope: scope, }) } @@ -523,6 +539,7 @@ func verifyWithEmail(c *fiber.Ctx, email, givenScope string) error { // @Summary verify with email in query and apikey // @Description verify with email in query, return verification code // @Tags account +// @Deprecated // @Produce json // @Router /verify/apikey [get] // @Param email query ApikeyRequest true "apikey, email" diff --git a/apis/schemas.go b/apis/schemas.go index 24bf758..9f37c5d 100644 --- a/apis/schemas.go +++ b/apis/schemas.go @@ -66,8 +66,9 @@ func (v *VerificationType) UnmarshalText(data []byte) error { } type EmailVerifyResponse struct { - Message string `json:"message"` - Scope string `json:"scope" enums:"register,reset"` + Message string `json:"message"` + Registered bool `json:"registered"` + Scope string `json:"scope" enums:"register,reset"` } type ApikeyRequest struct { diff --git a/docs/docs.go b/docs/docs.go index 0baf391..2b3db55 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -978,6 +978,7 @@ const docTemplate = `{ "account" ], "summary": "verify with email in query and apikey", + "deprecated": true, "parameters": [ { "type": "string", @@ -1049,6 +1050,12 @@ const docTemplate = `{ "description": "scope", "name": "scope", "in": "query" + }, + { + "type": "boolean", + "description": "check", + "name": "check", + "in": "query" } ], "responses": { @@ -1138,6 +1145,9 @@ const docTemplate = `{ "message": { "type": "string" }, + "registered": { + "type": "boolean" + }, "scope": { "type": "string", "enum": [ @@ -1153,6 +1163,9 @@ const docTemplate = `{ "message": { "type": "string" }, + "registered": { + "type": "boolean" + }, "scope": { "type": "string", "enum": [ diff --git a/docs/swagger.json b/docs/swagger.json index dd2214b..8a83d63 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -971,6 +971,7 @@ "account" ], "summary": "verify with email in query and apikey", + "deprecated": true, "parameters": [ { "type": "string", @@ -1042,6 +1043,12 @@ "description": "scope", "name": "scope", "in": "query" + }, + { + "type": "boolean", + "description": "check", + "name": "check", + "in": "query" } ], "responses": { @@ -1131,6 +1138,9 @@ "message": { "type": "string" }, + "registered": { + "type": "boolean" + }, "scope": { "type": "string", "enum": [ @@ -1146,6 +1156,9 @@ "message": { "type": "string" }, + "registered": { + "type": "boolean" + }, "scope": { "type": "string", "enum": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0550099..8ca3d45 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -6,6 +6,8 @@ definitions: type: string message: type: string + registered: + type: boolean scope: enum: - register @@ -16,6 +18,8 @@ definitions: properties: message: type: string + registered: + type: boolean scope: enum: - register @@ -961,6 +965,7 @@ paths: - user /verify/apikey: get: + deprecated: true description: verify with email in query, return verification code parameters: - in: query @@ -1010,6 +1015,10 @@ paths: in: query name: scope type: string + - description: check + in: query + name: check + type: boolean produces: - application/json responses: