summaryrefslogtreecommitdiff
path: root/mails.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-30 22:53:59 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-30 22:53:59 +0200
commitd4fe97a9a5437d71a5a29f413ba7be6efe5f7da3 (patch)
tree1df00e016300304318997e8f04053bf523b8d85e /mails.go
parent11ec26feeabced25281b8637f928a8096690c54b (diff)
downloadmailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.tar.gz
mailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.tar.bz2
mailremind-d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3.zip
Password reset implemented
Diffstat (limited to 'mails.go')
-rw-r--r--mails.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/mails.go b/mails.go
index 5e5a6dc..f4d6db5 100644
--- a/mails.go
+++ b/mails.go
@@ -18,7 +18,10 @@ func loadMailTpl(tplroot, name string) *template.Template {
return tpl
}
-var mailActivationcode *template.Template
+var (
+ mailActivationcode *template.Template
+ mailPwreset *template.Template
+)
func initMails() {
tplroot, err := conf.GetString("paths", "mailtpls")
@@ -27,6 +30,7 @@ func initMails() {
}
mailActivationcode = loadMailTpl(tplroot, "activationcode")
+ mailPwreset = loadMailTpl(tplroot, "pwreset")
}
type activationcodeData struct {
@@ -50,3 +54,21 @@ func SendActivationcode(to, acCode string, uid model.DBID) bool {
return Mail(to, MailFrom, buf.Bytes())
}
+
+func SendPwresetLink(to, code string, uid model.DBID) bool {
+ buf := new(bytes.Buffer)
+ fmt.Fprintf(buf, "To: %s\n", to)
+ fmt.Fprintf(buf, "From: %s\n", MailFrom)
+ fmt.Fprintf(buf, "Subject: Password reset request for your mailremind account\n")
+ fmt.Fprintf(buf, "Date: %s\n", time.Now().Format(time.RFC822))
+
+ fmt.Fprintln(buf, "")
+
+ url := fmt.Sprintf("%s/pwreset?U=%s&Code=%s", baseurl, uid, code)
+ if err := mailPwreset.Execute(buf, activationcodeData{url}); err != nil {
+ log.Printf("Error while executing mail template (pwreset): %s", err)
+ return false
+ }
+
+ return Mail(to, MailFrom, buf.Bytes())
+}