mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 08:17:05 +02:00
parent
600f0396d2
commit
712bdf734b
6
controller/email_ui/embed.go
Normal file
6
controller/email_ui/embed.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package email_ui
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed *.gohtml
|
||||||
|
var FS embed.FS
|
11
controller/email_ui/verify.gohtml
Normal file
11
controller/email_ui/verify.gohtml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Welcome to zrok!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to <code>zrok</code>, {{ .EmailAddress }}!</h1>
|
||||||
|
<p>Please click this <a href="{{ .VerifyUrl }}">link</a> to create your <code>zrok</code> account.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
41
controller/verify.go
Normal file
41
controller/verify.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/controller/email_ui"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"html/template"
|
||||||
|
"net/smtp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type verificationEmail struct {
|
||||||
|
EmailAddress string
|
||||||
|
VerifyUrl string
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVerificationEmail(emailAddress, token string, cfg *Config) error {
|
||||||
|
t, err := template.ParseFS(email_ui.FS, "verify.gohtml")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error parsing email verification template")
|
||||||
|
}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
err = t.Execute(buf, &verificationEmail{
|
||||||
|
EmailAddress: emailAddress,
|
||||||
|
VerifyUrl: cfg.Registration.RegistrationUrlTemplate + "/" + token,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error executing email verification template")
|
||||||
|
}
|
||||||
|
|
||||||
|
auth := smtp.PlainAuth("", cfg.Email.Username, cfg.Email.Password, cfg.Email.Host)
|
||||||
|
to := []string{emailAddress}
|
||||||
|
err = smtp.SendMail(fmt.Sprintf("%v:%d", cfg.Email.Host, cfg.Email.Port), auth, cfg.Registration.EmailFrom, to, buf.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error sending email verification")
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("verification email sent to '%v'", emailAddress)
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user