changed contact form reply_to and response html

This commit is contained in:
$(pass /github/name)
2024-08-21 12:29:13 +02:00
parent 3224536e56
commit ee66835649
5 changed files with 34 additions and 14 deletions

View File

@@ -15,7 +15,7 @@ type ContactController struct {
EmailService *services.EmailService
}
type contactData struct {
Email string `form:"email" validate:"required,email"`
Email string `form:"REPLY_TO" validate:"required,email"`
Name string `form:"name"`
Message string `form:"message" validate:"required"`
Honeypot string `form:"username" validate:"eq="`
@@ -32,16 +32,19 @@ func (cc *ContactController) RelayContactRequest(c *gin.Context) {
validate := validator.New()
if err := validate.Struct(msgData); err != nil {
logger.Error.Printf("Couldn't validate contact form data: %v", err)
c.JSON(http.StatusNotAcceptable, gin.H{"error": "Couldn't validate contact form data"})
logger.Error.Printf("Couldn't validate contact form data: %#v: %v", msgData, err)
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Error": "Form submission failed. Please try again."})
// c.JSON(http.StatusNotAcceptable, gin.H{"error": "Couldn't validate contact form data"})
return
}
if err := cc.EmailService.RelayContactFormMessage(msgData.Email, msgData.Name, msgData.Message); err != nil {
logger.Error.Printf("Couldn't send contact message mail: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Couldn't send mail"})
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Error": "Form submission failed. Please try again."})
// c.JSON(http.StatusInternalServerError, gin.H{"error": "Couldn't send mail"})
return
}
c.JSON(http.StatusAccepted, "Your message has been sent")
// c.JSON(http.StatusAccepted, "Your message has been sent")
c.HTML(http.StatusOK, "contactForm_reply.html", gin.H{"Success": true})
}

View File

@@ -95,7 +95,7 @@ func getBaseRequest() *url.Values {
return &url.Values{
"username": {""},
"name": {"My-First and-Last-Name"},
"email": {"name@domain.de"},
"REPLY_TO": {"name@domain.de"},
"message": {"My message to the world"},
}
}
@@ -116,7 +116,7 @@ func getContactData() []RelayContactRequestTest {
Assert: false,
Input: *customizeRequest(
map[string]string{
"email": "",
"REPLY_TO": "",
}),
},
{
@@ -125,7 +125,7 @@ func getContactData() []RelayContactRequestTest {
Assert: false,
Input: *customizeRequest(
map[string]string{
"email": "novalid#email.de",
"REPLY_TO": "novalid#email.de",
}),
},
{