42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package auth
|
|
|
|
import (
|
|
"quyun/v2/app/http/v1/dto"
|
|
"quyun/v2/app/services"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type Auth struct{}
|
|
|
|
// SendOTP sends an OTP to the provided phone number.
|
|
//
|
|
// @Router /v1/auth/otp [post]
|
|
// @Summary Send OTP
|
|
// @Description Send OTP to phone number
|
|
// @Tags Auth
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.SendOTPForm true "Phone number"
|
|
// @Success 200 {object} string "OTP sent"
|
|
// @Bind form body
|
|
func (a *Auth) SendOTP(ctx fiber.Ctx, form *dto.SendOTPForm) error {
|
|
return services.User.SendOTP(ctx.Context(), form.Phone)
|
|
}
|
|
|
|
// Login logs in or registers a user with OTP.
|
|
//
|
|
// @Router /v1/auth/login [post]
|
|
// @Summary Login or Register with OTP
|
|
// @Description Login or register user using phone number and OTP
|
|
// @Tags Auth
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.LoginForm true "Login form"
|
|
// @Success 200 {object} dto.LoginResponse
|
|
// @Bind form body
|
|
func (a *Auth) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
|
return services.User.LoginWithOTP(ctx.Context(), form.Phone, form.OTP)
|
|
}
|