Merge branch 'develop' into TM-295

This commit is contained in:
Nima Nakhsotin
2025-12-10 14:28:04 +03:30
9 changed files with 224 additions and 20 deletions
+5 -4
View File
@@ -4,10 +4,11 @@ import "tm/pkg/response"
// CreateContactForm represents the form for creating a new contact message
type CreateContactForm struct {
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Doe"`
Email string `json:"email" valid:"required,email" example:"john.doe@example.com"`
Phone string `json:"phone" valid:"required,length(10|20)" example:"+1234567890"`
Message string `json:"message" valid:"required,length(10|1000)" example:"I have a question about your services"`
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Doe"`
Email string `json:"email" valid:"required,email" example:"john.doe@example.com"`
Phone string `json:"phone" valid:"required,length(10|20)" example:"+1234567890"`
Message string `json:"message" valid:"required,length(10|1000)" example:"I have a question about your services"`
HCaptchaToken string `json:"hcaptcha_token" valid:"required" example:"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."`
}
// UpdateContactStatusForm represents the form for updating contact status (admin only)
+17 -3
View File
@@ -1,6 +1,7 @@
package contact
import (
"tm/pkg/hcaptcha"
"tm/pkg/response"
"github.com/labstack/echo/v4"
@@ -8,13 +9,15 @@ import (
// Handler handles HTTP requests for contact operations
type Handler struct {
service Service
service Service
hcaptchaVerifier hcaptcha.Verifier
}
// NewHandler creates a new contact handler
func NewHandler(service Service) *Handler {
func NewHandler(service Service, hcaptchaVerifier hcaptcha.Verifier) *Handler {
return &Handler{
service: service,
service: service,
hcaptchaVerifier: hcaptchaVerifier,
}
}
@@ -35,6 +38,17 @@ func (h *Handler) Create(c echo.Context) error {
return response.ValidationError(c, "Invalid request data", 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", "")
}
// Create contact
contact, err := h.service.Create(c.Request().Context(), form)
if err != nil {
+5 -4
View File
@@ -11,10 +11,11 @@ import (
// 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
+21 -7
View File
@@ -2,6 +2,7 @@ package inquiry
import (
"encoding/json"
"tm/pkg/hcaptcha"
"tm/pkg/logger"
"tm/pkg/response"
"tm/pkg/security"
@@ -11,17 +12,19 @@ import (
// Handler handles HTTP requests for inquiry operations
type Handler struct {
service Service
logger logger.Logger
xssPolicy *security.XSSPolicy
service Service
logger logger.Logger
hcaptchaVerifier hcaptcha.Verifier
xssPolicy *security.XSSPolicy
}
// NewInquiryHandler creates a new inquiry handler
func NewHandler(service Service, logger logger.Logger, xssPolicy *security.XSSPolicy) *Handler {
func NewHandler(service Service, logger logger.Logger, hcaptchaVerifier hcaptcha.Verifier, xssPolicy *security.XSSPolicy) *Handler {
return &Handler{
service: service,
logger: logger,
xssPolicy: xssPolicy,
service: service,
logger: logger,
hcaptchaVerifier: hcaptchaVerifier,
xssPolicy: xssPolicy,
}
}
@@ -49,6 +52,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 {