feat: update phone validation

This commit is contained in:
2025-12-20 11:52:08 +08:00
parent 0e4af79b53
commit 22e288bf98
6 changed files with 100 additions and 56 deletions

View File

@@ -18,11 +18,11 @@ type auth struct{}
// @Summary 手机验证 // @Summary 手机验证
// @Tags Auth // @Tags Auth
// @Produce json // @Produce json
// @Success 200 {object} requests.Pager{items=PostItem} "成功" // @Success 200 {object} any "成功"
// @Router /v1/auth/:phone [post] // @Router /v1/auth/phone [post]
// @Bind phone path // @Bind phone body
func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error { func (ctl *posts) Phone(ctx fiber.Ctx, form *PhoneValidation) error {
_, err := services.Users.FindByPhone(ctx, phone) _, err := services.Users.FindByPhone(ctx, form.Phone)
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.New("手机号未注册,请联系管理员开通") return errors.New("手机号未注册,请联系管理员开通")
@@ -32,3 +32,21 @@ func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error {
// TODO: send sms // TODO: send sms
return nil return nil
} }
type PhoneValidation struct {
Phone string `json:"phone,omitempty"`
Code *string `json:"code,omitempty"`
}
// Validate
//
// @Summary 手机验证
// @Tags Auth
// @Produce json
// @Success 200 {object} any "成功"
// @Router /v1/auth/validate [post]
// @Bind phone body
func (ctl *posts) Validate(ctx fiber.Ctx, form *PhoneValidation) error {
// TODO: send sms
return nil
}

View File

@@ -13,6 +13,13 @@ import (
) )
func Provide(opts ...opt.Option) error { func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func() (*auth, error) {
obj := &auth{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func( if err := container.Container.Provide(func(
app *app.Config, app *app.Config,
job *job.Job, job *job.Job,

View File

@@ -78,6 +78,14 @@ func (r *Routes) Register(router fiber.Router) {
Query[ListQuery]("query"), Query[ListQuery]("query"),
Local[*models.User]("user"), Local[*models.User]("user"),
)) ))
r.log.Debugf("Registering route: Post /v1/auth/phone -> posts.Phone")
router.Post("/v1/auth/phone"[len(r.Path()):], Func0(
r.posts.Phone,
))
r.log.Debugf("Registering route: Post /v1/auth/validate -> posts.Validate")
router.Post("/v1/auth/validate"[len(r.Path()):], Func0(
r.posts.Validate,
))
r.log.Debugf("Registering route: Post /v1/posts/:id/buy -> posts.Buy") r.log.Debugf("Registering route: Post /v1/posts/:id/buy -> posts.Buy")
router.Post("/v1/posts/:id/buy"[len(r.Path()):], DataFunc2( router.Post("/v1/posts/:id/buy"[len(r.Path()):], DataFunc2(
r.posts.Buy, r.posts.Buy,

View File

@@ -698,7 +698,7 @@ const docTemplate = `{
} }
} }
}, },
"/v1/auth/{phone}": { "/v1/auth/phone": {
"post": { "post": {
"produces": [ "produces": [
"application/json" "application/json"
@@ -710,21 +710,24 @@ const docTemplate = `{
"responses": { "responses": {
"200": { "200": {
"description": "成功", "description": "成功",
"schema": { "schema": {}
"allOf": [ }
{ }
"$ref": "#/definitions/requests.Pager" }
}, },
{ "/v1/auth/validate": {
"type": "object", "post": {
"properties": { "produces": [
"items": { "application/json"
"$ref": "#/definitions/http.PostItem" ],
} "tags": [
} "Auth"
} ],
] "summary": "手机验证",
} "responses": {
"200": {
"description": "成功",
"schema": {}
} }
} }
} }
@@ -1379,10 +1382,7 @@ const docTemplate = `{
"type": "integer" "type": "integer"
}, },
"metas": { "metas": {
"type": "array", "$ref": "#/definitions/types.JSONType-fields_MediaMetas"
"items": {
"type": "integer"
}
}, },
"mime_type": { "mime_type": {
"type": "string" "type": "string"
@@ -1589,6 +1589,9 @@ const docTemplate = `{
"types.JSONType-array_string": { "types.JSONType-array_string": {
"type": "object" "type": "object"
}, },
"types.JSONType-fields_MediaMetas": {
"type": "object"
},
"types.JSONType-fields_OrderMeta": { "types.JSONType-fields_OrderMeta": {
"type": "object" "type": "object"
}, },

View File

@@ -692,7 +692,7 @@
} }
} }
}, },
"/v1/auth/{phone}": { "/v1/auth/phone": {
"post": { "post": {
"produces": [ "produces": [
"application/json" "application/json"
@@ -704,21 +704,24 @@
"responses": { "responses": {
"200": { "200": {
"description": "成功", "description": "成功",
"schema": { "schema": {}
"allOf": [ }
{ }
"$ref": "#/definitions/requests.Pager" }
}, },
{ "/v1/auth/validate": {
"type": "object", "post": {
"properties": { "produces": [
"items": { "application/json"
"$ref": "#/definitions/http.PostItem" ],
} "tags": [
} "Auth"
} ],
] "summary": "手机验证",
} "responses": {
"200": {
"description": "成功",
"schema": {}
} }
} }
} }
@@ -1373,10 +1376,7 @@
"type": "integer" "type": "integer"
}, },
"metas": { "metas": {
"type": "array", "$ref": "#/definitions/types.JSONType-fields_MediaMetas"
"items": {
"type": "integer"
}
}, },
"mime_type": { "mime_type": {
"type": "string" "type": "string"
@@ -1583,6 +1583,9 @@
"types.JSONType-array_string": { "types.JSONType-array_string": {
"type": "object" "type": "object"
}, },
"types.JSONType-fields_MediaMetas": {
"type": "object"
},
"types.JSONType-fields_OrderMeta": { "types.JSONType-fields_OrderMeta": {
"type": "object" "type": "object"
}, },

View File

@@ -229,9 +229,7 @@ definitions:
id: id:
type: integer type: integer
metas: metas:
items: $ref: '#/definitions/types.JSONType-fields_MediaMetas'
type: integer
type: array
mime_type: mime_type:
type: string type: string
name: name:
@@ -367,6 +365,8 @@ definitions:
type: object type: object
types.JSONType-array_string: types.JSONType-array_string:
type: object type: object
types.JSONType-fields_MediaMetas:
type: object
types.JSONType-fields_OrderMeta: types.JSONType-fields_OrderMeta:
type: object type: object
types.JSONType-fields_UserAuthToken: types.JSONType-fields_UserAuthToken:
@@ -830,20 +830,25 @@ paths:
summary: 调整用户余额 summary: 调整用户余额
tags: tags:
- Admin Users - Admin Users
/v1/auth/{phone}: /v1/auth/phone:
post: post:
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: 成功 description: 成功
schema: schema: {}
allOf: summary: 手机验证
- $ref: '#/definitions/requests.Pager' tags:
- properties: - Auth
items: /v1/auth/validate:
$ref: '#/definitions/http.PostItem' post:
type: object produces:
- application/json
responses:
"200":
description: 成功
schema: {}
summary: 手机验证 summary: 手机验证
tags: tags:
- Auth - Auth