diff --git a/src/main/java/csse/users/UserHttpController.java b/src/main/java/csse/users/UserHttpController.java index c5c3073..cae06b9 100644 --- a/src/main/java/csse/users/UserHttpController.java +++ b/src/main/java/csse/users/UserHttpController.java @@ -71,15 +71,13 @@ public void deactivate(@RequestBody List users) { public String resetPassword(@PathVariable(value="username") String username, @RequestBody Map body) { String newp=body.get("new"); String currentp=body.get("current"); - String confirmp=body.get("confirm"); - return service.resetPassword(username, currentp, newp, confirmp); + return service.resetPassword(username, currentp, newp); } @PatchMapping("/forgotpassword/{username}") public String forgotPassword(@PathVariable(value="username") String username, @RequestBody Map body) { String np=body.get("new"); - String confirmp=body.get("confirm"); - return service.forgotPassword(username, np, confirmp); + return service.forgotPassword(username, np); } } \ No newline at end of file diff --git a/src/main/java/csse/users/UserService.java b/src/main/java/csse/users/UserService.java index 6b516c2..105ba95 100644 --- a/src/main/java/csse/users/UserService.java +++ b/src/main/java/csse/users/UserService.java @@ -91,7 +91,7 @@ public ApplicationUser findByemp(String ID) { //reset password through profile //@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER')") - public String resetPassword(String username, String cpwd, String npwd, String confirm) { + public String resetPassword(String username, String cpwd, String npwd) { ApplicationUser u=repo.findByUsername(username); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); @@ -102,30 +102,27 @@ public String resetPassword(String username, String cpwd, String npwd, String co // if(u.getPassword().equals(cpwd)) { if(encoder.matches(cpwd, u.getPassword())) { - if(npwd.equals(confirm)) { + u.setPassword(bCryptPasswordEncoder.encode(npwd)); //u.setPassword(npwd); u.setModifiedDate(d); repo.save(u); return "Password reset successfully"; - } - return "The new passwords don't match"; + } return "Current password is incorrect!"; } //reset password through forgot passWord //@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER')") - public String forgotPassword(String username, String np, String confirm) { + public String forgotPassword(String username, String np) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date date = new Date(); String d=dateFormat.format(date); - ApplicationUser u= repo.findByUsername(username); - if(np.equals(confirm)) { - + ApplicationUser u= repo.findByUsername(username); u.setPassword(bCryptPasswordEncoder.encode(np)); //u.setPassword(np); @@ -133,8 +130,7 @@ public String forgotPassword(String username, String np, String confirm) { repo.save(u); return "Password reset successfully"; - } - return "Password reset failed"; + } //edit user profile diff --git a/src/test/java/csse/UserServiceTests.java b/src/test/java/csse/UserServiceTests.java index 3beccdc..af4c436 100644 --- a/src/test/java/csse/UserServiceTests.java +++ b/src/test/java/csse/UserServiceTests.java @@ -106,23 +106,16 @@ public void setsUserIdOnSaveTest() throws Exception { // @Test // public void resetPasswordPassedTest() throws Exception { // logger.info("Running pass resetPassword"); -// String response = service.resetPassword("Sam99", "Sam99", "sam99", "sam99"); +// String response = service.resetPassword("Sam99", "Sam99", "sam99"); // Assert.assertEquals("user's pwd is reset", "Password reset successfully", response); // // } + // @Test // public void resetPasswordFailTest() throws Exception { // logger.info("Running fail resetPassword"); -// String response = service.resetPassword("Sam99", "Sam99", "sam88", "sam99"); -// Assert.assertEquals("user's pwd is not reset", "The new passwords don't match", response); -// -// } - -// @Test -// public void resetPasswordFailTest() throws Exception { -// logger.info("Running fail resetPassword"); -// String response = service.resetPassword("Sam99", "Sam9999", "sam99", "sam99"); +// String response = service.resetPassword("Sam99", "Sam9999", "sam99"); // Assert.assertEquals("user's pwd is not reset", "Current password is incorrect!", response); // // } @@ -131,18 +124,11 @@ public void setsUserIdOnSaveTest() throws Exception { // @Test // public void forgotPasswordPassTest() throws Exception { // logger.info("Running pass forgotPassword"); -// String response = service.forgotPassword("Mathew99", "math", "math"); +// String response = service.forgotPassword("Mathew99", "math"); // Assert.assertEquals("user's pwd is reset", "Password reset successfully", response); // // } -// @Test -// public void forgotPasswordFailTest() throws Exception { -// logger.info("Running fail forgotPassword"); -// String response = service.forgotPassword("Mathew99", "math123", "math"); -// Assert.assertEquals("user's pwd is not reset", "Password reset failed", response); -// -// } // // @Test