Compare commits
No commits in common. "7b340cc6f4ab4ac9bd688d906e6d139125d54e3e" and "7e57bd218fc5cfe6cc0fc71e6e3f513295b070a8" have entirely different histories.
7b340cc6f4
...
7e57bd218f
7
.envrc
7
.envrc
|
@ -1,7 +0,0 @@
|
||||||
use_configsh() {
|
|
||||||
watch_file config.sh
|
|
||||||
eval "$(cat config.sh)"
|
|
||||||
}
|
|
||||||
|
|
||||||
use_flake
|
|
||||||
use_configsh
|
|
43
flake.lock
43
flake.lock
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"futils": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1656928814,
|
|
||||||
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1659526864,
|
|
||||||
"narHash": "sha256-XFzXrc1+6DZb9hBgHfEzfwylPUSqVFJbQPs8eOgYufU=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "478f3cbc8448b5852539d785fbfe9a53304133be",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-22.05",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"futils": "futils",
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
32
flake.nix
32
flake.nix
|
@ -1,32 +0,0 @@
|
||||||
{
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
|
|
||||||
futils.url = "github:numtide/flake-utils";
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, futils } @ inputs:
|
|
||||||
let
|
|
||||||
inherit (nixpkgs) lib;
|
|
||||||
inherit (lib) recursiveUpdate;
|
|
||||||
inherit (futils.lib) eachDefaultSystem;
|
|
||||||
|
|
||||||
nixpkgsImport = system:
|
|
||||||
import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
|
|
||||||
defaultSystemOutputs = eachDefaultSystem (system:
|
|
||||||
let
|
|
||||||
pkgs = nixpkgsImport system;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
devShells.default = pkgs.mkShell {
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
git
|
|
||||||
go
|
|
||||||
];
|
|
||||||
};
|
|
||||||
});
|
|
||||||
in
|
|
||||||
defaultSystemOutputs;
|
|
||||||
}
|
|
9
main.go
9
main.go
|
@ -17,10 +17,10 @@ limitations under the License.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -72,9 +72,10 @@ func main() {
|
||||||
viper.SetDefault("SMTP_SERVER_ADDR", "127.0.0.1:465")
|
viper.SetDefault("SMTP_SERVER_ADDR", "127.0.0.1:465")
|
||||||
viper.SetDefault("SMTP_CLIENT_USERNAME", "")
|
viper.SetDefault("SMTP_CLIENT_USERNAME", "")
|
||||||
viper.SetDefault("SMTP_CLIENT_PASSWORD", "")
|
viper.SetDefault("SMTP_CLIENT_PASSWORD", "")
|
||||||
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@example.com")
|
viper.SetDefault("CONTACT_REPLY_EMAIL", "noreply@company.com")
|
||||||
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@example.com")
|
viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com")
|
||||||
viper.SetDefault("EMAIL_SUBJECT", "New message from contact form")
|
viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product")
|
||||||
|
viper.SetDefault("DEMO_URL", "http://company.com/product-demo")
|
||||||
viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true)
|
viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true)
|
||||||
|
|
||||||
host := os.Getenv("HOST")
|
host := os.Getenv("HOST")
|
||||||
|
|
45
sendmail.go
45
sendmail.go
|
@ -22,12 +22,12 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/dpapathanasiou/go-recaptcha"
|
"github.com/dpapathanasiou/go-recaptcha"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -67,7 +67,7 @@ func NewSendMailRequest(from string, to []string, subject string) *SendMailReque
|
||||||
// Execute processes the actual email sending
|
// Execute processes the actual email sending
|
||||||
func (m *SendMailRequest) Execute() error {
|
func (m *SendMailRequest) Execute() error {
|
||||||
|
|
||||||
mime := "MIME-version: 1.0;\nContent-Type: text/plain; charset=\"UTF-8\";\n\n"
|
mime := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
|
||||||
from := "From: " + m.from + "\n"
|
from := "From: " + m.from + "\n"
|
||||||
subject := "Subject: " + m.subject + "\n"
|
subject := "Subject: " + m.subject + "\n"
|
||||||
msg := []byte(from + subject + mime + "\n" + m.body)
|
msg := []byte(from + subject + mime + "\n" + m.body)
|
||||||
|
@ -222,12 +222,25 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
contactRequest := ContactRequest{
|
contactRequest := ContactRequest{
|
||||||
Name: httpReq.FormValue("name"),
|
Name: httpReq.FormValue("name"),
|
||||||
Email: strings.TrimSpace(httpReq.FormValue("email")),
|
Email: strings.TrimSpace(httpReq.FormValue("email")),
|
||||||
|
Organization: httpReq.FormValue("organization"),
|
||||||
Subject: httpReq.FormValue("subject"),
|
Subject: httpReq.FormValue("subject"),
|
||||||
Message: httpReq.FormValue("message"),
|
Message: httpReq.FormValue("message"),
|
||||||
|
RequestTarget: httpReq.FormValue("target"),
|
||||||
OriginURI: httpReq.FormValue("requestOrigin"),
|
OriginURI: httpReq.FormValue("requestOrigin"),
|
||||||
}
|
}
|
||||||
|
|
||||||
recipients := []string{viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
var recipients []string
|
||||||
|
switch contactRequest.RequestTarget {
|
||||||
|
case "demo":
|
||||||
|
recipients = []string{contactRequest.Email, viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
||||||
|
case "contact":
|
||||||
|
recipients = []string{viper.GetString("CONTACT_REPLY_BCC_EMAIL")}
|
||||||
|
default:
|
||||||
|
log.Println("not allowed request type:", contactRequest.RequestTarget)
|
||||||
|
httpResp.WriteHeader(http.StatusForbidden)
|
||||||
|
httpResp.Write([]byte(`{"status": "error", "message": "unauthorized request"}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
userData, _ := json.Marshal(contactRequest)
|
userData, _ := json.Marshal(contactRequest)
|
||||||
log.Println("New Request:", string(userData))
|
log.Println("New Request:", string(userData))
|
||||||
|
@ -235,25 +248,37 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
templateData := struct {
|
templateData := struct {
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
|
Organization string
|
||||||
Subject string
|
Subject string
|
||||||
Message string
|
Message string
|
||||||
|
DemoURL string
|
||||||
}{
|
}{
|
||||||
Name: contactRequest.Name,
|
Name: contactRequest.Name,
|
||||||
Email: contactRequest.Email,
|
Email: contactRequest.Email,
|
||||||
|
Organization: contactRequest.Organization,
|
||||||
Subject: contactRequest.Subject,
|
Subject: contactRequest.Subject,
|
||||||
Message: contactRequest.Message,
|
Message: contactRequest.Message,
|
||||||
|
DemoURL: viper.GetString("DEMO_URL"),
|
||||||
}
|
}
|
||||||
|
|
||||||
replyTplFile := viper.GetString("TEMPLATE_CONTACT_REQUEST_REPLY")
|
replyTplFile := ""
|
||||||
|
if contactRequest.RequestTarget == "demo" {
|
||||||
|
replyTplFile = viper.GetString("TEMPLATE_DEMO_REQUEST_REPLY")
|
||||||
if replyTplFile == "" {
|
if replyTplFile == "" {
|
||||||
replyTplFile = "./templates/template_reply_contact_request.txt"
|
replyTplFile = "./templates/template_reply_demo_request.html"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replyTplFile = viper.GetString("TEMPLATE_CONTACT_REQUEST_REPLY")
|
||||||
|
if replyTplFile == "" {
|
||||||
|
replyTplFile = "./templates/template_reply_contact_request.html"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contactEmail := viper.GetString("CONTACT_REPLY_EMAIL")
|
contactEmail := viper.GetString("CONTACT_REPLY_EMAIL")
|
||||||
sendMailReq := NewSendMailRequest(
|
sendMailReq := NewSendMailRequest(
|
||||||
contactEmail,
|
contactEmail,
|
||||||
recipients,
|
recipients,
|
||||||
viper.GetString("EMAIL_SUBJECT"),
|
contactRequest.Subject,
|
||||||
)
|
)
|
||||||
err := sendMailReq.ParseTemplate(replyTplFile, templateData)
|
err := sendMailReq.ParseTemplate(replyTplFile, templateData)
|
||||||
|
|
||||||
|
@ -263,10 +288,14 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
contactResponse.Status = "error"
|
contactResponse.Status = "error"
|
||||||
contactResponse.Message = fmt.Sprintf("An internal error occurred, please try later.")
|
contactResponse.Message = fmt.Sprintf("An internal error occurred, please try later or send us an email at %s.", viper.GetString("CONTACT_REPLY_BCC_EMAIL"))
|
||||||
} else {
|
} else {
|
||||||
contactResponse.Status = "success"
|
contactResponse.Status = "success"
|
||||||
contactResponse.Message = "Thank you for your message."
|
if contactRequest.RequestTarget == "demo" {
|
||||||
|
contactResponse.Message = "Thank you, if you supplied a correct email address then an email should have been sent to you."
|
||||||
|
} else {
|
||||||
|
contactResponse.Message = "Thank you, if you supplied a correct email address then we'll process your request within the next 48 hours."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<p>Hi,</p>
|
||||||
|
<p>A new contact request has been submitted by Mr/Mrs {{.Name}}.</p>
|
||||||
|
<ul>
|
||||||
|
<li>Name: {{.Name}}</li>
|
||||||
|
<li>Email: {{.Email}}</li>
|
||||||
|
<li>Organization: {{.Organization}}</li>
|
||||||
|
<li>Subject: {{.Subject}}</li>
|
||||||
|
<li>Message: {{.Message}}</li>
|
||||||
|
</ul>
|
||||||
|
--
|
||||||
|
<p>This is an automatic email from Krossboard's website.</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -1,12 +0,0 @@
|
||||||
Hello,
|
|
||||||
|
|
||||||
A new message has been received on the contact form.
|
|
||||||
|
|
||||||
Name: {{.Name}}
|
|
||||||
Email: {{.Email}}
|
|
||||||
Subject: {{.Subject}}
|
|
||||||
|
|
||||||
{{.Message}}
|
|
||||||
|
|
||||||
--
|
|
||||||
Automatic email from F5KCK Website
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<p>Dear Mr/Mrs {{.Name}},</p>
|
||||||
|
<p>
|
||||||
|
Thank you for your interest in our products.
|
||||||
|
You'll find below information to get access to the demo platform.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>URL: <a href="{{.DemoURL}}">{{.DemoURL}}</a></li>
|
||||||
|
<li>Login: demo</li>
|
||||||
|
<li>Password: password</li>
|
||||||
|
</ul>
|
||||||
|
<p>Enjoy and don't hesitate to contact us if you do have any feedback.</p>
|
||||||
|
<p>
|
||||||
|
Kind regards,<br/>
|
||||||
|
The Customer Service Team
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<legend>Summary of your request</legend>
|
||||||
|
<ul>
|
||||||
|
<li>Name: {{.Name}}</li>
|
||||||
|
<li>Email: {{.Email}}</li>
|
||||||
|
<li>Organization: {{.Organization}}</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue