func TestUser_Change_Passwd_In_ValidCurrent(t *testing.T) { //UserChangePassword initUser(nil) c := dbConn() req, err := models.UserSignIn(c, "*****@*****.**", "test1234", "password") if err != nil { t.Fatalf("login failed unexpectedly") return } u, err := models.VerifyUserRequest(c, req.AccessToken) if _, err := models.UserChangePassword(c, u, "test12355", "test12345"); err == nil { t.Fatalf("password change was unexpectedly successful") return } }
func (h *Handler) authenticationPasswordChangeService(w http.ResponseWriter, r *http.Request, u *sitrep.UsersByEmail) { req, err := unmarshalPasswordChangeRequest(r) if err != nil { httpError(w, "Password could not be changed", false, http.StatusInternalServerError) return } if req.NewPassword != req.NewPasswordConfirmation { httpError(w, "Passwords do not match", false, http.StatusExpectationFailed) return } if req.OldPassword == "" { httpError(w, "Old password is empty", false, http.StatusExpectationFailed) return } pwChange, err := models.UserChangePassword(h.Cassandra, u, req.OldPassword, req.NewPassword) if err != nil { httpError(w, err.Error(), false, http.StatusForbidden) return } w.Header().Add("content-type", "application/json") w.Write(MarshalJSON(pwChange, false)) }