1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: minor code restyling

This commit is contained in:
Ferdinand Mütsch
2020-10-16 16:11:14 +02:00
parent c575b2fd5c
commit a4c344aaa1
7 changed files with 77 additions and 49 deletions

View File

@ -59,7 +59,7 @@ func (h *SettingsHandler) PostCredentials(w http.ResponseWriter, r *http.Request
return
}
if !utils.CheckPasswordBcrypt(user, credentials.PasswordOld, h.config.Security.PasswordSalt) {
if !utils.CompareBcrypt(user.Password, credentials.PasswordOld, h.config.Security.PasswordSalt) {
respondAlert(w, "invalid credentials", "", conf.SettingsTemplate, http.StatusUnauthorized)
return
}
@ -70,9 +70,11 @@ func (h *SettingsHandler) PostCredentials(w http.ResponseWriter, r *http.Request
}
user.Password = credentials.PasswordNew
if err := utils.HashPassword(user, h.config.Security.PasswordSalt); err != nil {
if hash, err := utils.HashBcrypt(user.Password, h.config.Security.PasswordSalt); err != nil {
respondAlert(w, "internal server error", "", conf.SettingsTemplate, http.StatusInternalServerError)
return
} else {
user.Password = hash
}
if _, err := h.userSrvc.Update(user); err != nil {