()
| 175 | } |
| 176 | |
| 177 | func (this *LoginedController) ChangePassword() { |
| 178 | old := this.GetString("old") |
| 179 | newPwd := this.GetString("new") |
| 180 | repeatPwd := this.GetString("repeat") |
| 181 | |
| 182 | if old == "" || newPwd == "" || repeatPwd == "" { |
| 183 | this.Response(http.StatusBadRequest, "原密码、新密码和确认密码均不能为空") |
| 184 | } |
| 185 | |
| 186 | if count := strings.Count(newPwd, ""); count < 6 || count > 18 { |
| 187 | this.Response(http.StatusBadRequest, "密码必须在 6 - 18 字符之间") |
| 188 | } |
| 189 | |
| 190 | if newPwd != repeatPwd { |
| 191 | this.Response(http.StatusBadRequest, "新密码和确认密码不一致") |
| 192 | } |
| 193 | |
| 194 | if old == newPwd { |
| 195 | this.Response(http.StatusBadRequest, "新密码和原密码不能相同") |
| 196 | } |
| 197 | |
| 198 | member, err := models.NewMember().Find(this.isLogin()) |
| 199 | if err != nil { |
| 200 | beego.Error(err.Error()) |
| 201 | this.Response(http.StatusInternalServerError, messageInternalServerError) |
| 202 | } |
| 203 | |
| 204 | if ok, _ := utils.PasswordVerify(member.Password, old); !ok { |
| 205 | this.Response(http.StatusBadRequest, "原密码不正确") |
| 206 | } |
| 207 | |
| 208 | pwd, err := utils.PasswordHash(newPwd) |
| 209 | if err != nil { |
| 210 | beego.Error(err.Error()) |
| 211 | this.Response(http.StatusInternalServerError, messageInternalServerError) |
| 212 | } |
| 213 | |
| 214 | member.Password = pwd |
| 215 | member.Update() |
| 216 | if err != nil { |
| 217 | beego.Error(err.Error()) |
| 218 | this.Response(http.StatusInternalServerError, messageInternalServerError) |
| 219 | } |
| 220 | this.Response(http.StatusOK, messageSuccess) |
| 221 | } |
| 222 | |
| 223 | // 执行签到 |
| 224 | func (this *LoginedController) SignToday() { |
nothing calls this directly
no test coverage detected