From d4fe97a9a5437d71a5a29f413ba7be6efe5f7da3 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 30 Aug 2013 22:53:59 +0200 Subject: Password reset implemented --- mails.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'mails.go') 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()) +} -- cgit v1.2.3-54-g00ecf