MCPcopy Index your code
hub / github.com/TruthHun/BookStack / ChangePassword

Method ChangePassword

controllers/api/LoginedController.go:177–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175}
176
177func (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// 执行签到
224func (this *LoginedController) SignToday() {

Callers

nothing calls this directly

Calls 8

NewMemberFunction · 0.92
PasswordVerifyFunction · 0.92
PasswordHashFunction · 0.92
ResponseMethod · 0.80
isLoginMethod · 0.80
CountMethod · 0.45
FindMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected