修改密码
()
| 64 | |
| 65 | // 修改密码 |
| 66 | func (this *SettingController) Password() { |
| 67 | |
| 68 | if this.Ctx.Input.IsPost() { |
| 69 | if this.Member.AuthMethod == conf.AuthMethodLDAP { |
| 70 | this.JsonResult(6009, "当前用户不支持修改密码") |
| 71 | } |
| 72 | password1 := this.GetString("password1") |
| 73 | password2 := this.GetString("password2") |
| 74 | password3 := this.GetString("password3") |
| 75 | if password1 == "" { |
| 76 | this.JsonResult(6003, "原密码不能为空") |
| 77 | } |
| 78 | |
| 79 | if password2 == "" { |
| 80 | this.JsonResult(6004, "新密码不能为空") |
| 81 | } |
| 82 | |
| 83 | if count := strings.Count(password2, ""); count < 6 || count > 18 { |
| 84 | this.JsonResult(6009, "密码必须在6-18字之间") |
| 85 | } |
| 86 | |
| 87 | if password2 != password3 { |
| 88 | this.JsonResult(6003, "确认密码不正确") |
| 89 | } |
| 90 | |
| 91 | if ok, _ := utils.PasswordVerify(this.Member.Password, password1); !ok { |
| 92 | this.JsonResult(6005, "原始密码不正确") |
| 93 | } |
| 94 | |
| 95 | if password1 == password2 { |
| 96 | this.JsonResult(6006, "新密码不能和原始密码相同") |
| 97 | } |
| 98 | |
| 99 | pwd, err := utils.PasswordHash(password2) |
| 100 | if err != nil { |
| 101 | this.JsonResult(6007, "密码加密失败") |
| 102 | } |
| 103 | |
| 104 | this.Member.Password = pwd |
| 105 | if err := this.Member.Update(); err != nil { |
| 106 | this.JsonResult(6008, err.Error()) |
| 107 | } |
| 108 | |
| 109 | this.JsonResult(0, "ok") |
| 110 | } |
| 111 | |
| 112 | this.Data["SettingPwd"] = true |
| 113 | this.Data["SeoTitle"] = "修改密码 - " + this.Sitename |
| 114 | this.TplName = "setting/password.html" |
| 115 | } |
| 116 | |
| 117 | // 收藏 |
| 118 | func (this *SettingController) Star() { |
nothing calls this directly
no test coverage detected