Password resets

This commit is contained in:
Harvey Tindall
2020-08-01 16:31:08 +01:00
parent 4e16f6fd48
commit c4d4b395d5
5 changed files with 130 additions and 0 deletions
+32
View File
@@ -158,6 +158,38 @@ func (email *Emailer) constructCreated(code, username, address string, invite In
return nil
}
func (email *Emailer) constructReset(pwr Pwr, ctx *appContext) error {
email.content.subject = ctx.config.Section("password_resets").Key("subject").MustString("Password reset - Jellyfin")
d, t, expires_in := email.formatExpiry(pwr.Expiry, true, ctx.datePattern, ctx.timePattern)
message := ctx.config.Section("email").Key("message").String()
for _, key := range []string{"html", "text"} {
fpath := ctx.config.Section("password_resets").Key("email_" + key).String()
tpl, err := template.ParseFiles(fpath)
if err != nil {
return err
}
var tplData bytes.Buffer
err = tpl.Execute(&tplData, map[string]string{
"username": pwr.Username,
"expiry_date": d,
"expiry_time": t,
"expires_in": expires_in,
"pin": pwr.Pin,
"message": message,
})
if err != nil {
return err
}
if key == "html" {
email.content.html = tplData.String()
} else {
email.content.text = tplData.String()
}
}
email.sendType = "reset"
return nil
}
func (email *Emailer) send(address string, ctx *appContext) error {
if email.sendMethod == "mailgun" {
message := email.mg.NewMessage(