added hcaptcha

This commit is contained in:
Mazyar
2025-12-05 18:10:05 +03:30
parent b8a10f355e
commit b01c0f9368
9 changed files with 222 additions and 18 deletions
+5 -4
View File
@@ -6,10 +6,11 @@ import "tm/pkg/response"
// CreateInquiryForm represents the data required to create a new inquiry
type CreateInquiryForm struct {
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Doe"` // Full name of the inquirer
CompanyName string `json:"company_name" valid:"required,length(2|100)" example:"Opplens"` // Company name
WorkEmail string `json:"work_email" valid:"required,email" example:"info@opplens.com"` // Work email address
PhoneNumber string `json:"phone_number" valid:"required,length(10|20)" example:"+1234567890"` // Phone number
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Doe"` // Full name of the inquirer
CompanyName string `json:"company_name" valid:"required,length(2|100)" example:"Opplens"` // Company name
WorkEmail string `json:"work_email" valid:"required,email" example:"info@opplens.com"` // Work email address
PhoneNumber string `json:"phone_number" valid:"required,length(10|20)" example:"+1234567890"` // Phone number
HCaptchaToken string `json:"hcaptcha_token" valid:"required" example:"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."`
}
// UpdateInquiryStatusForm represents the data required to update inquiry status
+19 -5
View File
@@ -2,6 +2,7 @@ package inquiry
import (
"encoding/json"
"tm/pkg/hcaptcha"
"tm/pkg/logger"
"tm/pkg/response"
@@ -11,15 +12,17 @@ import (
// Handler handles HTTP requests for inquiry operations
type Handler struct {
service Service
logger logger.Logger
service Service
logger logger.Logger
hcaptchaVerifier hcaptcha.Verifier
}
// NewInquiryHandler creates a new inquiry handler
func NewHandler(service Service, logger logger.Logger) *Handler {
func NewHandler(service Service, logger logger.Logger, hcaptchaVerifier hcaptcha.Verifier) *Handler {
return &Handler{
service: service,
logger: logger,
service: service,
logger: logger,
hcaptchaVerifier: hcaptchaVerifier,
}
}
@@ -47,6 +50,17 @@ func (h *Handler) CreateInquiry(c echo.Context) error {
return response.ValidationError(c, err.Error(), "")
}
// Verify hCaptcha token
remoteIP := c.RealIP()
verificationResponse, err := h.hcaptchaVerifier.Verify(form.HCaptchaToken, remoteIP)
if err != nil {
return response.BadRequest(c, "Failed to verify hCaptcha token", "")
}
if !verificationResponse.Success {
return response.BadRequest(c, "hCaptcha verification failed", "")
}
// Call service
inquiry, err := h.service.Create(c.Request().Context(), form)
if err != nil {