passes subject and email body as parameters

This commit is contained in:
Giorgos Komninos 2021-08-08 20:05:12 +03:00
parent b521f4bfa9
commit 1bb3370e07
3 changed files with 15 additions and 4 deletions

View file

@ -189,7 +189,7 @@ func NewClient() echo.HandlerFunc {
} }
// EmailClient handler to sent the configuration via email // 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 { type clientIdEmailPayload struct {
ID string `json:"id"` ID string `json:"id"`
Email string `json:"email"` Email string `json:"email"`
@ -220,8 +220,8 @@ func EmailClient(mailer emailer.Emailer) echo.HandlerFunc {
err = mailer.Send( err = mailer.Send(
clientData.Client.Name, clientData.Client.Name,
payload.Email, payload.Email,
"Your Wireguard configuration", emailSubject,
"instructions here", emailContent,
[]emailer.Attachment{cfg_att, qr_att}, []emailer.Attachment{cfg_att, qr_att},
) )
if err != nil { if err != nil {

11
main.go
View file

@ -24,6 +24,15 @@ var (
buildTime = fmt.Sprintf(time.Now().UTC().Format("01-02-2006 15:04:05")) buildTime = fmt.Sprintf(time.Now().UTC().Format("01-02-2006 15:04:05"))
) )
const (
defaultEmailSubject = "Your wireguard configuration"
defaultEmailContent = `Hi,</br>
<p>in this email you can file your personal configuration for our wireguard server.</p>
<p>Best</p>
`
)
func init() { func init() {
// command-line flags // command-line flags
flagDisableLogin := flag.Bool("disable-login", false, "Disable login page. Turn off authentication.") 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.GET("/logout", handler.Logout(), handler.ValidSession)
app.POST("/new-client", handler.NewClient(), handler.ValidSession) app.POST("/new-client", handler.NewClient(), handler.ValidSession)
app.POST("/update-client", handler.UpdateClient(), 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("/client/set-status", handler.SetClientStatus(), handler.ValidSession)
app.POST("/remove-client", handler.RemoveClient(), handler.ValidSession) app.POST("/remove-client", handler.RemoveClient(), handler.ValidSession)
app.GET("/download", handler.DownloadClient(), handler.ValidSession) app.GET("/download", handler.DownloadClient(), handler.ValidSession)

View file

@ -7,5 +7,7 @@ var (
SendgridApiKey string SendgridApiKey string
EmailFrom string EmailFrom string
EmailFromName string EmailFromName string
EmailSubject string
EmailContent string
SessionSecret []byte SessionSecret []byte
) )