From 1bb3370e073d0a150424aaf9d0092e54bc970f90 Mon Sep 17 00:00:00 2001 From: Giorgos Komninos Date: Sun, 8 Aug 2021 20:05:12 +0300 Subject: [PATCH] passes subject and email body as parameters --- handler/routes.go | 6 +++--- main.go | 11 ++++++++++- util/config.go | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/handler/routes.go b/handler/routes.go index c16c14b..22df3d7 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -189,7 +189,7 @@ func NewClient() echo.HandlerFunc { } // EmailClient handler to sent the configuration via email -func EmailClient(mailer emailer.Emailer) echo.HandlerFunc { +func EmailClient(mailer emailer.Emailer, emailSubject, emailContent string) echo.HandlerFunc { type clientIdEmailPayload struct { ID string `json:"id"` Email string `json:"email"` @@ -220,8 +220,8 @@ func EmailClient(mailer emailer.Emailer) echo.HandlerFunc { err = mailer.Send( clientData.Client.Name, payload.Email, - "Your Wireguard configuration", - "instructions here", + emailSubject, + emailContent, []emailer.Attachment{cfg_att, qr_att}, ) if err != nil { diff --git a/main.go b/main.go index 47fdb15..2e9e5cd 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,15 @@ var ( buildTime = fmt.Sprintf(time.Now().UTC().Format("01-02-2006 15:04:05")) ) +const ( + defaultEmailSubject = "Your wireguard configuration" + defaultEmailContent = `Hi,
+

in this email you can file your personal configuration for our wireguard server.

+ +

Best

+` +) + func init() { // command-line flags flagDisableLogin := flag.Bool("disable-login", false, "Disable login page. Turn off authentication.") @@ -81,7 +90,7 @@ func main() { app.GET("/logout", handler.Logout(), handler.ValidSession) app.POST("/new-client", handler.NewClient(), handler.ValidSession) app.POST("/update-client", handler.UpdateClient(), handler.ValidSession) - app.POST("/email-client", handler.EmailClient(sendmail), handler.ValidSession) + app.POST("/email-client", handler.EmailClient(sendmail, defaultEmailSubject, defaultEmailContent), handler.ValidSession) app.POST("/client/set-status", handler.SetClientStatus(), handler.ValidSession) app.POST("/remove-client", handler.RemoveClient(), handler.ValidSession) app.GET("/download", handler.DownloadClient(), handler.ValidSession) diff --git a/util/config.go b/util/config.go index 6ec77a4..5f86ea9 100644 --- a/util/config.go +++ b/util/config.go @@ -7,5 +7,7 @@ var ( SendgridApiKey string EmailFrom string EmailFromName string + EmailSubject string + EmailContent string SessionSecret []byte )