找回密码.
()
| 406 | |
| 407 | //找回密码. |
| 408 | func (this *AccountController) FindPassword() { |
| 409 | |
| 410 | this.TplName = "account/find_password_setp1.html" |
| 411 | mailConf := conf.GetMailConfig() |
| 412 | |
| 413 | if this.Ctx.Input.IsPost() { |
| 414 | |
| 415 | email := this.GetString("email") |
| 416 | |
| 417 | if email == "" { |
| 418 | this.JsonResult(6005, "邮箱地址不能为空") |
| 419 | } |
| 420 | if !mailConf.EnableMail { |
| 421 | this.JsonResult(6004, "未启用邮件服务") |
| 422 | } |
| 423 | |
| 424 | //captcha := this.GetString("code") |
| 425 | //如果开启了验证码 |
| 426 | //if v, ok := this.Option["ENABLED_CAPTCHA"]; ok && strings.EqualFold(v, "true") { |
| 427 | // v, ok := this.GetSession(conf.CaptchaSessionName).(string) |
| 428 | // if !ok || !strings.EqualFold(v, captcha) { |
| 429 | // this.JsonResult(6001, "验证码不正确") |
| 430 | // } |
| 431 | //} |
| 432 | |
| 433 | if !cpt.VerifyReq(this.Ctx.Request) { |
| 434 | this.JsonResult(6001, "验证码不正确") |
| 435 | } |
| 436 | |
| 437 | member, err := models.NewMember().FindByFieldFirst("email", email) |
| 438 | if err != nil { |
| 439 | beego.Error(err) |
| 440 | this.JsonResult(6006, "邮箱不存在") |
| 441 | } |
| 442 | if member.Status != 0 { |
| 443 | this.JsonResult(6007, "账号已被禁用") |
| 444 | } |
| 445 | if member.AuthMethod == conf.AuthMethodLDAP { |
| 446 | this.JsonResult(6011, "当前用户不支持找回密码") |
| 447 | } |
| 448 | |
| 449 | count, err := models.NewMemberToken().FindSendCount(email, time.Now().Add(-1*time.Hour), time.Now()) |
| 450 | |
| 451 | if err != nil { |
| 452 | beego.Error(err) |
| 453 | this.JsonResult(6008, "发送邮件失败") |
| 454 | } |
| 455 | if count > mailConf.MailNumber { |
| 456 | this.JsonResult(6008, "发送次数太多,请稍候再试") |
| 457 | } |
| 458 | |
| 459 | memberToken := models.NewMemberToken() |
| 460 | |
| 461 | memberToken.Token = string(utils.Krand(32, utils.KC_RAND_KIND_ALL)) |
| 462 | memberToken.Email = email |
| 463 | memberToken.MemberId = member.MemberId |
| 464 | memberToken.IsValid = false |
| 465 | if _, err := memberToken.InsertOrUpdate(); err != nil { |
nothing calls this directly
no test coverage detected