feat: update phone validation
This commit is contained in:
@@ -18,11 +18,11 @@ type auth struct{}
|
||||
// @Summary 手机验证
|
||||
// @Tags Auth
|
||||
// @Produce json
|
||||
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
|
||||
// @Router /v1/auth/:phone [post]
|
||||
// @Bind phone path
|
||||
func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error {
|
||||
_, err := services.Users.FindByPhone(ctx, phone)
|
||||
// @Success 200 {object} any "成功"
|
||||
// @Router /v1/auth/phone [post]
|
||||
// @Bind phone body
|
||||
func (ctl *posts) Phone(ctx fiber.Ctx, form *PhoneValidation) error {
|
||||
_, err := services.Users.FindByPhone(ctx, form.Phone)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.New("手机号未注册,请联系管理员开通")
|
||||
@@ -32,3 +32,21 @@ func (ctl *posts) Phone(ctx fiber.Ctx, phone string) error {
|
||||
// TODO: send sms
|
||||
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
|
||||
}
|
||||
|
||||
@@ -13,6 +13,13 @@ import (
|
||||
)
|
||||
|
||||
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(
|
||||
app *app.Config,
|
||||
job *job.Job,
|
||||
|
||||
@@ -78,6 +78,14 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
Query[ListQuery]("query"),
|
||||
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")
|
||||
router.Post("/v1/posts/:id/buy"[len(r.Path()):], DataFunc2(
|
||||
r.posts.Buy,
|
||||
|
||||
Reference in New Issue
Block a user