func ForgotPasswdPost(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("auth.forgot_password") if setting.MailService == nil { ctx.Handle(403, "user.ForgotPasswdPost", nil) return } ctx.Data["IsResetRequest"] = true email := ctx.Query("email") u, err := models.GetUserByEmail(email) if err != nil { if err == models.ErrUserNotExist { ctx.Data["Err_Email"] = true ctx.RenderWithErr(ctx.Tr("auth.email_not_associate"), FORGOT_PASSWORD, nil) } else { ctx.Handle(500, "user.ResetPasswd(check existence)", err) } return } if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) { ctx.Data["ResendLimited"] = true ctx.HTML(200, FORGOT_PASSWORD) return } mailer.SendResetPasswdMail(ctx.Render, u) if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { log.Error(4, "Set cache(MailResendLimit) fail: %v", err) } ctx.Data["Email"] = email ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60 ctx.Data["IsResetSent"] = true ctx.HTML(200, FORGOT_PASSWORD) }
func ForgotPasswdPost(ctx *middleware.Context) { ctx.Data["Title"] = "Forgot Password" if base.MailService == nil { ctx.Handle(403, "user.ForgotPasswdPost", nil) return } ctx.Data["IsResetRequest"] = true email := ctx.Query("email") u, err := models.GetUserByEmail(email) if err != nil { if err == models.ErrUserNotExist { ctx.RenderWithErr("This e-mail address does not associate to any account.", "user/forgot_passwd", nil) } else { ctx.Handle(500, "user.ResetPasswd(check existence)", err) } return } if ctx.Cache.IsExist("MailResendLimit_" + u.LowerName) { ctx.Data["ResendLimited"] = true ctx.HTML(200, "user/forgot_passwd") return } mailer.SendResetPasswdMail(ctx.Render, u) if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) } ctx.Data["Email"] = email ctx.Data["Hours"] = base.Service.ActiveCodeLives / 60 ctx.Data["IsResetSent"] = true ctx.HTML(200, "user/forgot_passwd") }