Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final changes #87

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/main/java/csse/users/UserHttpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ public void deactivate(@RequestBody List<ApplicationUser> users) {
public String resetPassword(@PathVariable(value="username") String username, @RequestBody Map<String, String> 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<String, String> body) {
String np=body.get("new");
String confirmp=body.get("confirm");
return service.forgotPassword(username, np, confirmp);
return service.forgotPassword(username, np);
}
}
16 changes: 6 additions & 10 deletions src/main/java/csse/users/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -102,39 +102,35 @@ 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);
u.setModifiedDate(d);

repo.save(u);
return "Password reset successfully";
}
return "Password reset failed";

}

//edit user profile
Expand Down
22 changes: 4 additions & 18 deletions src/test/java/csse/UserServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//
// }
Expand All @@ -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
Expand Down