dethnote/src/verify_email.go

49 lines
1.0 KiB
Go

package dethnote
import (
"bytes"
"fmt"
"net/http"
"git.kirsle.net/apps/dethnote/src/vault"
"github.com/gorilla/mux"
)
// VerifyHandler is the callback when a user verifies their email.
func (s *Server) VerifyHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
token := vars["token"]
path := vars["path"]
_, _ = token, path
}
// SendVerificationEmail sends a verification email.
func (s *Server) SendVerificationEmail(r *http.Request, m *vault.Message) error {
base := URLBase(r)
hashPath := vault.HashToFilename(m.PasswordHash)
v := map[string]interface{}{
"Subject": "Verify Your Email",
"VerifyLink": fmt.Sprintf("%s/verify/%s/%s",
base,
m.VerifyToken,
hashPath,
),
"DeleteLink": fmt.Sprintf("%s/delete/%s",
base,
hashPath,
),
}
html := bytes.NewBuffer([]byte{})
s.Template(html, "mail/verify-email.gohtml", v)
err := s.SendMail(Mail{
From: "noreply@kirsle.net", // TODO
To: m.Email,
Subject: v["Subject"].(string),
HTML: html.String(),
})
return err
}