diff --git a/models/user.go b/models/user.go index 5e7ddad86..ea23938bb 100755 --- a/models/user.go +++ b/models/user.go @@ -1625,6 +1625,26 @@ func GetUserByEmail(email string) (*User, error) { return GetUserByEmailContext(DefaultDBContext(), email) } +func GetUserByMainEmail(email string) (*User, error) { + if len(email) == 0 { + return nil, ErrUserNotExist{0, email, 0} + } + + email = strings.ToLower(email) + // First try to find the user by primary email + user := &User{Email: email} + has, err := DefaultDBContext().e.Get(user) + if err != nil { + return nil, err + } + if has { + return user, nil + } else { + return nil, ErrUserNotExist{0, email, 0} + } + +} + // GetUserByEmailContext returns the user object by given e-mail if exists with db context func GetUserByEmailContext(ctx DBContext, email string) (*User, error) { if len(email) == 0 { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 70d76d407..7cf271c27 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -335,6 +335,8 @@ resent_limit_prompt = You have already requested an activation email recently. P has_unconfirmed_mail = Hi %s, you have an unconfirmed email address (%s). If you haven't received a confirmation email or need to resend a new one, please click on the button below. resend_mail = Click here to resend your activation email email_not_associate = The email address is not associated with any account. +email_not_main=The email address is wrong, please input your primary email address. +email_not_right=The email address is not associated with any account, please input the right email address. send_reset_mail = Send Account Recovery Email reset_password = Account Recovery invalid_code = Your confirmation code is invalid or has expired. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index b66cdbb21..415b85bfe 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -339,6 +339,8 @@ resent_limit_prompt=您请求发送激活邮件过于频繁,请等待 3 分钟 has_unconfirmed_mail=%s 您好,系统检测到您有一封发送至 %s 但未被确认的邮件。如果您未收到激活邮件,或需要重新发送,请单击下方的按钮。 resend_mail=单击此处重新发送确认邮件 email_not_associate=您输入的邮箱地址未被关联到任何帐号! +email_not_main=电子邮箱地址不正确,请输入您设置的主要邮箱地址。 +email_not_right=您输入了不存在的邮箱地址,请输入正确的邮箱地址。 send_reset_mail=发送账户恢复邮件 reset_password=账户恢复 invalid_code=此确认密钥无效或已过期。 diff --git a/routers/user/auth.go b/routers/user/auth.go index c3af2b8d4..0de15f5f5 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1425,12 +1425,16 @@ func ForgotPasswdPost(ctx *context.Context) { email := ctx.Query("email") ctx.Data["Email"] = email - u, err := models.GetUserByEmail(email) + u, err := models.GetUserByMainEmail(email) if err != nil { if models.IsErrUserNotExist(err) { ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) - ctx.Data["IsResetSent"] = true - ctx.HTML(200, tplForgotPassword) + ctx.Data["IsResetSent"] = false + if used, _ := models.IsEmailUsed(email); used { + ctx.RenderWithErr(ctx.Tr("auth.email_not_main"), tplForgotPassword, nil) + } else { + ctx.RenderWithErr(ctx.Tr("auth.email_not_right"), tplForgotPassword, nil) + } return }