找回密码
()
| 539 | |
| 540 | // 找回密码 |
| 541 | func (this *UserController) FindPwd() { |
| 542 | if this.IsLogin > 0 { |
| 543 | this.Redirect("/user", 302) |
| 544 | return |
| 545 | } |
| 546 | |
| 547 | if this.Ctx.Request.Method == "GET" { |
| 548 | this.Data["Seo"] = models.NewSeo().GetByPage("PC-Findpwd", "找回密码", "找回密码", "找回密码", this.Sys.Site) |
| 549 | this.Data["IsUser"] = true |
| 550 | this.Data["PageId"] = "wenku-reg" |
| 551 | this.TplName = "findpwd.html" |
| 552 | return |
| 553 | } |
| 554 | |
| 555 | rules := map[string][]string{ |
| 556 | "username": {"required", "mincount:2", "maxcount:16"}, |
| 557 | "email": {"required", "email"}, |
| 558 | "code": {"required", "len:6"}, |
| 559 | "password": {"required", "mincount:6"}, |
| 560 | "repassword": {"required", "mincount:6"}, |
| 561 | } |
| 562 | |
| 563 | params, errs := helper.Valid(this.Ctx.Request.Form, rules) |
| 564 | if len(errs) > 0 { |
| 565 | if _, ok := errs["username"]; ok { |
| 566 | this.ResponseJson(false, "用户名限2-16个字符") |
| 567 | } |
| 568 | if _, ok := errs["email"]; ok { |
| 569 | this.ResponseJson(false, "邮箱格式不正确") |
| 570 | } |
| 571 | if _, ok := errs["code"]; ok { |
| 572 | this.ResponseJson(false, "请输入6位验证码") |
| 573 | } |
| 574 | if _, ok := errs["password"]; ok { |
| 575 | this.ResponseJson(false, "密码长度,至少6个字符") |
| 576 | } |
| 577 | if _, ok := errs["repassword"]; ok { |
| 578 | this.ResponseJson(false, "密码长度,至少6个字符") |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | //校验验证码和邮箱是否匹配 |
| 583 | if fmt.Sprintf("%v", this.GetSession("FindPwdMail")) != params["email"].(string) || fmt.Sprintf("%v", this.GetSession("FindPwdCode")) != params["code"].(string) { |
| 584 | this.ResponseJson(false, "验证码不正确,修改密码失败") |
| 585 | } |
| 586 | pwd := helper.MD5Crypt(params["password"].(string)) |
| 587 | repwd := helper.MD5Crypt(params["repassword"].(string)) |
| 588 | if pwd != repwd { |
| 589 | this.ResponseJson(false, "确认密码和密码不一致") |
| 590 | } |
| 591 | |
| 592 | user := models.NewUser().GetUserField(orm.NewCondition().And("Email", params["email"])) |
| 593 | if user.Id == 0 || user.Username != params["username"].(string) { |
| 594 | this.ResponseJson(false, "重置密码失败,用户名与邮箱不匹配") |
| 595 | } |
| 596 | |
| 597 | _, err := models.UpdateByIds("user", "Password", pwd, user.Id) |
| 598 | if err != nil { |
nothing calls this directly
no test coverage detected