use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserController method setNewPassword.
@PostMapping(value = "/reset")
public ResponseEntity<?> setNewPassword(@RequestBody Map<String, String> requestParams) {
User user = urepo.findByTokenPassword(requestParams.get("token"));
HttpHeaders responseHeaders = new HttpHeaders();
if (user != null) {
user.setPassword(bCryptPasswordEncoder.encode(requestParams.get("password")));
user.setTokenPassword(null);
urepo.save(user);
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 updateEmailError.
// Method sending an error message for the former email adress
public boolean updateEmailError(String email) {
User user = urepo.findByEmail(email);
if (user != null) {
SimpleMailMessage infoUpdateFail = new SimpleMailMessage();
infoUpdateFail.setFrom(SENDFROM);
infoUpdateFail.setTo(user.getEmail());
infoUpdateFail.setSubject("Suspicious access to your account");
infoUpdateFail.setText("We have registered a suspicious activity on your acccount");
mailSender.send(infoUpdateFail);
return true;
}
return false;
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class AuthenticationRestControllerTest method successfulRefreshTokenWithUserRole.
@Test
@WithMockUser(roles = "USER")
public void successfulRefreshTokenWithUserRole() throws Exception {
Authority authority = new Authority();
authority.setId(0L);
authority.setName(AuthorityName.ROLE_USER);
List<Authority> authorities = Arrays.asList(authority);
User user = new User();
user.setUsername("username");
user.setAuthorities(authorities);
user.setEnabled(Boolean.TRUE);
user.setLastPasswordResetDate(new Date(System.currentTimeMillis() + 1000 * 1000));
JwtUser jwtUser = JwtUserFactory.create(user);
when(this.jwtTokenUtil.getUsernameFromToken(any())).thenReturn(user.getUsername());
when(this.userDetailsService.loadUserByUsername(eq(user.getUsername()))).thenReturn(jwtUser);
when(this.jwtTokenUtil.canTokenBeRefreshed(any(), any())).thenReturn(true);
this.mvc.perform(get("/refresh").header("Authorization", "Bearer 5d1103e-b3e1-4ae9-b606-46c9c1bc915a")).andExpect(status().is2xxSuccessful());
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class AuthenticationRestControllerTest method successfulRefreshTokenWithAdminRole.
@Test
@WithMockUser(roles = "ADMIN")
public void successfulRefreshTokenWithAdminRole() throws Exception {
Authority authority = new Authority();
authority.setId(1L);
authority.setName(AuthorityName.ROLE_ADMIN);
List<Authority> authorities = Arrays.asList(authority);
User user = new User();
user.setUsername("admin");
user.setAuthorities(authorities);
user.setEnabled(Boolean.TRUE);
user.setLastPasswordResetDate(new Date(System.currentTimeMillis() + 1000 * 1000));
JwtUser jwtUser = JwtUserFactory.create(user);
when(this.jwtTokenUtil.getUsernameFromToken(any())).thenReturn(user.getUsername());
when(this.userDetailsService.loadUserByUsername(eq(user.getUsername()))).thenReturn(jwtUser);
when(this.jwtTokenUtil.canTokenBeRefreshed(any(), any())).thenReturn(true);
this.mvc.perform(get("/refresh").header("Authorization", "Bearer 5d1103e-b3e1-4ae9-b606-46c9c1bc915a")).andExpect(status().is2xxSuccessful());
}
use of fr.codechill.spring.model.User in project code-chill by CodeChillAlluna.
the class UserRestControllerTest method getPersonsSuccessfullyWithUserRole.
@Test
@WithMockUser(roles = "USER")
public void getPersonsSuccessfullyWithUserRole() throws Exception {
Authority authority = new Authority();
authority.setId(1L);
authority.setName(AuthorityName.ROLE_ADMIN);
List<Authority> authorities = Arrays.asList(authority);
User user = new User();
user.setUsername("username");
user.setAuthorities(authorities);
user.setEnabled(Boolean.TRUE);
user.setLastPasswordResetDate(new Date(System.currentTimeMillis() + 1000 * 1000));
JwtUser jwtUser = JwtUserFactory.create(user);
when(this.jwtTokenUtil.getUsernameFromToken(any())).thenReturn(user.getUsername());
when(this.userDetailsService.loadUserByUsername(eq(user.getUsername()))).thenReturn(jwtUser);
this.mvc.perform(get("/user").header("Authorization", "Bearer nsodunsodiuv")).andExpect(status().is2xxSuccessful());
}
Aggregations