Search in sources :

Example 1 with User

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));
}
Also used : User(fr.codechill.spring.model.User) Docker(fr.codechill.spring.model.Docker) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with User

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;
}
Also used : User(fr.codechill.spring.model.User) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 3 with 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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) User(fr.codechill.spring.model.User) Calendar(java.util.Calendar) Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with User

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;
}
Also used : User(fr.codechill.spring.model.User) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 5 with User

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) User(fr.codechill.spring.model.User) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

User (fr.codechill.spring.model.User)10 Date (java.util.Date)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Authority (fr.codechill.spring.model.security.Authority)3 JwtUser (fr.codechill.spring.security.JwtUser)3 HttpHeaders (org.springframework.http.HttpHeaders)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Docker (fr.codechill.spring.model.Docker)1 Calendar (java.util.Calendar)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1