use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserTest method testAddDocker.
@Test
public void testAddDocker() {
User userTest = new User(this.nom, this.prenom);
Docker dockerTest = new Docker(this.nomDocker);
userTest.addDocker(dockerTest);
assertEquals(true, userTest.getDockers().contains(dockerTest));
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserController method editUser.
@PutMapping("/user")
public User editUser(@RequestHeader(value = "Authorization") String token, @RequestBody User user) {
String username = jwtTokenUtil.getUsernameFromToken(token.substring(7));
User updatedUser = this.urepo.findByUsername(username);
if (!updatedUser.getLastname().equals(user.getLastname())) {
updatedUser.setLastname(user.getLastname());
}
if (!updatedUser.getFirstname().equals(user.getFirstname())) {
updatedUser.setFirstname(user.getFirstname());
}
if (!updatedUser.getEmail().equals(user.getEmail())) {
updatedUser.setEmail(user.getEmail());
updateUserEmail(updatedUser.getEmail());
}
this.urepo.save(updatedUser);
return user;
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserController method resetPassword.
@GetMapping(value = "/reset/{token}")
public ResponseEntity<?> resetPassword(@PathVariable("token") String token) {
HttpHeaders responseHeaders = new HttpHeaders();
User user = urepo.findByTokenPassword(token);
Date currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(user.getLastPasswordResetDate());
c.add(Calendar.DATE, 1);
Date currentDatePlusOne = c.getTime();
if (user != null) {
if (currentDate.after(user.getLastPasswordResetDate()) && currentDate.before(currentDatePlusOne)) {
return ResponseEntity.ok().headers(responseHeaders).body(user);
}
}
return ResponseEntity.badRequest().headers(responseHeaders).body(null);
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserController method deleteUser.
@DeleteMapping("/user")
public Boolean deleteUser(@RequestHeader(value = "Authorization") String token) {
String username = jwtTokenUtil.getUsernameFromToken(token.substring(7));
User user = this.urepo.findByUsername(username);
this.urepo.delete(user);
return true;
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserController method processForgotPasswordForm.
// Process form submission from forgotPassword page
@PostMapping(value = "/user/forgottenpassword")
public ResponseEntity<?> processForgotPasswordForm(@RequestBody String email) {
User user = urepo.findByEmail(email);
HttpHeaders responseHeaders = new HttpHeaders();
if (user != null) {
user.setLastPasswordResetDate(new Date());
user.setTokenPassword(UUID.randomUUID().toString());
user = urepo.save(user);
SimpleMailMessage passwordResetEmail = new SimpleMailMessage();
passwordResetEmail.setFrom(SENDFROM);
passwordResetEmail.setTo(user.getEmail());
passwordResetEmail.setSubject("Password Reset Request");
passwordResetEmail.setText("Reset link:\n" + BASE_URL + "/reset/" + user.getTokenPassword());
mailSender.send(passwordResetEmail);
return ResponseEntity.ok().headers(responseHeaders).body(user);
}
return ResponseEntity.badRequest().headers(responseHeaders).body(user);
}
Aggregations