|
|
|
@@ -50,13 +50,14 @@ const ( |
|
|
|
// tplSignUp template path for sign up page |
|
|
|
tplSignUp base.TplName = "user/auth/signup" |
|
|
|
// TplActivate template path for activate user |
|
|
|
TplActivate base.TplName = "user/auth/activate" |
|
|
|
tplForgotPassword base.TplName = "user/auth/forgot_passwd" |
|
|
|
tplResetPassword base.TplName = "user/auth/reset_passwd" |
|
|
|
tplTwofa base.TplName = "user/auth/twofa" |
|
|
|
tplTwofaScratch base.TplName = "user/auth/twofa_scratch" |
|
|
|
tplLinkAccount base.TplName = "user/auth/link_account" |
|
|
|
tplU2F base.TplName = "user/auth/u2f" |
|
|
|
TplActivate base.TplName = "user/auth/activate" |
|
|
|
tplForgotPassword base.TplName = "user/auth/forgot_passwd" |
|
|
|
tplForgotPasswordPhone base.TplName = "user/auth/forgot_passwd_phone" |
|
|
|
tplResetPassword base.TplName = "user/auth/reset_passwd" |
|
|
|
tplTwofa base.TplName = "user/auth/twofa" |
|
|
|
tplTwofaScratch base.TplName = "user/auth/twofa_scratch" |
|
|
|
tplLinkAccount base.TplName = "user/auth/link_account" |
|
|
|
tplU2F base.TplName = "user/auth/u2f" |
|
|
|
) |
|
|
|
|
|
|
|
// AutoSignIn reads cookie and try to auto-login. |
|
|
|
@@ -1398,18 +1399,30 @@ func ActivateEmail(ctx *context.Context) { |
|
|
|
// ForgotPasswd render the forget pasword page |
|
|
|
func ForgotPasswd(ctx *context.Context) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("auth.forgot_password_title") |
|
|
|
forgetType := ctx.Query("type") |
|
|
|
|
|
|
|
if setting.MailService == nil { |
|
|
|
ctx.Data["IsResetDisable"] = true |
|
|
|
ctx.HTML(200, tplForgotPassword) |
|
|
|
return |
|
|
|
} |
|
|
|
if forgetType == "phone" { |
|
|
|
if !setting.PhoneService.Enabled { |
|
|
|
ctx.Data["IsResetDisable"] = true |
|
|
|
ctx.HTML(200, tplForgotPasswordPhone) |
|
|
|
return |
|
|
|
} |
|
|
|
ctx.Data["IsResetRequest"] = true |
|
|
|
ctx.HTML(200, tplForgotPasswordPhone) |
|
|
|
} else { |
|
|
|
|
|
|
|
email := ctx.Query("email") |
|
|
|
ctx.Data["Email"] = email |
|
|
|
if setting.MailService == nil { |
|
|
|
ctx.Data["IsResetDisable"] = true |
|
|
|
ctx.HTML(200, tplForgotPassword) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["IsResetRequest"] = true |
|
|
|
ctx.HTML(200, tplForgotPassword) |
|
|
|
email := ctx.Query("email") |
|
|
|
ctx.Data["Email"] = email |
|
|
|
|
|
|
|
ctx.Data["IsResetRequest"] = true |
|
|
|
ctx.HTML(200, tplForgotPassword) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ForgotPasswdPost response for forget password request |
|
|
|
@@ -1622,6 +1635,55 @@ func ResetPasswdPost(ctx *context.Context) { |
|
|
|
handleSignInFull(ctx, u, remember, true) |
|
|
|
} |
|
|
|
|
|
|
|
func ResetPasswdByPhonePost(ctx *context.Context, form auth.ResetPassWordByPhoneForm) { |
|
|
|
phoneNumber := strings.TrimSpace(form.PhoneNumber) |
|
|
|
verifyCode := strings.TrimSpace(form.VerifyCode) |
|
|
|
isRight := phoneService.IsVerifyCodeRight(phoneNumber, verifyCode) |
|
|
|
if !isRight { |
|
|
|
ctx.RenderWithErr(ctx.Tr("phone.verify_code_fail"), tplForgotPasswordPhone, form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
passwd := strings.TrimSpace(form.Password) |
|
|
|
if len(passwd) < setting.MinPasswordLength { |
|
|
|
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplForgotPasswordPhone, form) |
|
|
|
return |
|
|
|
} else if !password.IsComplexEnough(passwd) { |
|
|
|
ctx.RenderWithErr(password.BuildComplexityError(ctx), tplForgotPasswordPhone, form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
u, err := models.GetUserByPhoneNumber(phoneNumber) |
|
|
|
if err != nil { |
|
|
|
log.Error("fail to query by phone number", err) |
|
|
|
ctx.RenderWithErr(ctx.Tr("phone.query_err", setting.MinPasswordLength), tplForgotPasswordPhone, form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if nil != ctx.User && u.ID != ctx.User.ID { |
|
|
|
ctx.RenderWithErr(ctx.Tr("auth.reset_password_wrong_user", ctx.User.Email, u.Email), tplForgotPasswordPhone, form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if u.Rands, err = models.GetUserSalt(); err != nil { |
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
return |
|
|
|
} |
|
|
|
if u.Salt, err = models.GetUserSalt(); err != nil { |
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
return |
|
|
|
} |
|
|
|
u.HashPassword(passwd) |
|
|
|
u.MustChangePassword = false |
|
|
|
if err := models.UpdateUserCols(u, "must_change_password", "passwd", "rands", "salt"); err != nil { |
|
|
|
ctx.ServerError("UpdateUser", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
handleSignInFull(ctx, u, form.Remember, true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// MustChangePassword renders the page to change a user's password |
|
|
|
func MustChangePassword(ctx *context.Context) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("auth.must_change_password") |
|
|
|
|