Spaces:
Running
Running
Commit ·
360774b
1
Parent(s): c11601b
Deploy files from GitHub repository
Browse files
controllers/email_verification_controller.go
CHANGED
|
@@ -30,7 +30,7 @@ func NewEmailVerificationController(emailVerificationService services.EmailVerif
|
|
| 30 |
// @Accept json
|
| 31 |
// @Produce json
|
| 32 |
// @Param request body dto.CreateEmailVerificationRequest true "Create Email Verification Request"
|
| 33 |
-
// @Success 200 {object} dto.SuccessResponse[
|
| 34 |
// @Failure 400 {object} dto.ErrorResponse
|
| 35 |
// @Router /api/v1/email/create-verification [post]
|
| 36 |
func (c *emailVerificationController) Create(ctx *gin.Context) {
|
|
@@ -38,7 +38,16 @@ func (c *emailVerificationController) Create(ctx *gin.Context) {
|
|
| 38 |
token := uint(rand.Intn(900000) + 100000)
|
| 39 |
due := time.Now().Add(15 * time.Minute)
|
| 40 |
res, err := c.emailVerificationService.CreateToken(ctx.Request.Context(), req.Email, token, due)
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
// Validate Email Verification godoc
|
|
|
|
| 30 |
// @Accept json
|
| 31 |
// @Produce json
|
| 32 |
// @Param request body dto.CreateEmailVerificationRequest true "Create Email Verification Request"
|
| 33 |
+
// @Success 200 {object} dto.SuccessResponse[dto.CreateEmailVerificationResponse]
|
| 34 |
// @Failure 400 {object} dto.ErrorResponse
|
| 35 |
// @Router /api/v1/email/create-verification [post]
|
| 36 |
func (c *emailVerificationController) Create(ctx *gin.Context) {
|
|
|
|
| 38 |
token := uint(rand.Intn(900000) + 100000)
|
| 39 |
due := time.Now().Add(15 * time.Minute)
|
| 40 |
res, err := c.emailVerificationService.CreateToken(ctx.Request.Context(), req.Email, token, due)
|
| 41 |
+
if err != nil {
|
| 42 |
+
ResponseJSON(ctx, req, dto.CreateEmailVerificationResponse{}, err)
|
| 43 |
+
return
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
ResponseJSON(ctx, req, dto.CreateEmailVerificationResponse{
|
| 47 |
+
Email: req.Email,
|
| 48 |
+
Token: res.Token,
|
| 49 |
+
ExpiredAt: res.ExpiredAt,
|
| 50 |
+
}, nil)
|
| 51 |
}
|
| 52 |
|
| 53 |
// Validate Email Verification godoc
|
models/dto/email_verification_dto.go
CHANGED
|
@@ -1,5 +1,13 @@
|
|
| 1 |
-
package dto
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package dto
|
| 2 |
+
|
| 3 |
+
import "time"
|
| 4 |
+
|
| 5 |
+
type DeleteEmailVerificationRequest struct {
|
| 6 |
+
Token uint `json:"token" binding:"required"`
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
type CreateEmailVerificationResponse struct {
|
| 10 |
+
Email string `json:"email"`
|
| 11 |
+
Token uint `json:"token"`
|
| 12 |
+
ExpiredAt time.Time `json:"expired_at"`
|
| 13 |
+
}
|
services/supabase_email_verification_service.go
CHANGED
|
@@ -45,7 +45,7 @@ func NewSupabaseEmailVerificationService(supabaseConfig config.SupabaseConfig) S
|
|
| 45 |
supabaseURL: baseURL,
|
| 46 |
serviceKey: serviceKey,
|
| 47 |
smtp: smtp,
|
| 48 |
-
httpClient: &http.Client{Timeout:
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
|
|
|
| 45 |
supabaseURL: baseURL,
|
| 46 |
serviceKey: serviceKey,
|
| 47 |
smtp: smtp,
|
| 48 |
+
httpClient: &http.Client{Timeout: 5 * time.Minute},
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|