Skip to content

Commit c01e526

Browse files
committed
resend otp done
1 parent 14561ac commit c01e526

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

pkg/controller/auth.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ func VerifyOTP(c echo.Context) error {
345345
})
346346
}
347347

348+
func ResendOTP(c echo.Context) error {
349+
ctx := c.Request().Context()
350+
var req models.ResendOTP
351+
err := utils.GenerateOTP(ctx, req.Email)
352+
if err != nil {
353+
logger.Errorf(logger.InternalError, err.Error())
354+
355+
return c.JSON(http.StatusInternalServerError, &models.Response{
356+
Status: "fail",
357+
Message: "Failed to generate OTP",
358+
})
359+
}
360+
361+
return c.JSON(http.StatusOK, &models.Response{
362+
Status: "success",
363+
Message: "OTP has been sent to email",
364+
})
365+
}
366+
348367
func Login(c echo.Context) error {
349368
ctx := c.Request().Context()
350369
var req models.LoginRequest

pkg/models/auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ type UpdatePasswordRequest struct {
3131
NewPassword string `json:"new_password" validate:"required"`
3232
OTP string `json:"otp" validate:"required"`
3333
}
34+
35+
type ResendOTP struct {
36+
Email string `json:"email"`
37+
}

pkg/router/auth_routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func AuthRoutes(incomingRoutes *echo.Group) {
1818
auth.GET("/star", controller.CheckStarred, middleware.JWTMiddleware())
1919
auth.POST("/github", controller.UpdateGithubProfile, middleware.JWTMiddleware())
2020
auth.POST("/logout", controller.Logout)
21+
auth.POST("/resend-otp", controller.ResendOTP)
2122

2223
// auth.Use(middleware.JWTMiddleware())
2324
// auth.GET("/ping", controller.Ping)

0 commit comments

Comments
 (0)