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 手机验证
// @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
}