use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class ContactUtils method listUsersWithDetail.
// endregion
// region Users
public static void listUsersWithDetail(Collection<User> users) {
System.out.println("LISTING ENTITIES WITH DETAILS ---------------------------------");
System.out.println();
for (User user : users) {
System.out.println(user);
if (user.getAuthorities() != null) {
user.getAuthorities().forEach(System.out::println);
}
// if (user.getUserProfile() != null) {
// System.out.println(user.getUserProfile());
// }
System.out.println();
}
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class UserPasswordControllerTests method loggedInUserPasswordIsUpdated.
@Test
public void loggedInUserPasswordIsUpdated() throws Exception {
RequestBuilder request = post("/users/resetpassword").param("userId", "4").param("password", "password").param("repeatedPassword", "password").with(csrf());
mvc.perform(request);
Optional<User> user = userService.getUserById(4L);
if (user.isPresent()) {
String encodedPassword = user.get().getPassword();
assertTrue(new BCryptPasswordEncoder().matches("password", encodedPassword));
}
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class SecurityTests method validRegistration_UserCreatedButNotApproved.
// endregion
// region Registration Form
@Test
public void validRegistration_UserCreatedButNotApproved() throws Exception {
mvc.perform(post("/register").param("username", "bobby").param("firstName", "Bob").param("lastName", "Crachet").param("email", "bob@aol.com").param("password", "password").param("repeatedPassword", "password").with(csrf()));
User bobby = userService.getUserByUsername("bobby");
assertNotNull(bobby.getUserData().getCreatedDatetime());
assertNull(bobby.getUserData().getApprovedDatetime());
assertFalse(bobby.isEnabled());
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class UserController method register.
@RequestMapping(value = "/register", method = POST)
public String register(@Valid @ModelAttribute("userDTO") UserDTO userDTO, BindingResult result, WebRequest request, RedirectAttributes redirectAttributes) {
if (webUI.isNixMash()) {
return "redirect:/";
}
if (result.hasErrors()) {
return REGISTER_VIEW;
}
userDTO.setSignInProvider(SignInProvider.SITE);
userDTO.setAuthorities(Lists.newArrayList(new Authority("ROLE_USER")));
// todo: Add SiteOptions.AuthenticationType for optional setEnabled(false)
userDTO.setEnabled(false);
User user = userService.create(userDTO);
String redirectionUrl = "redirect:/";
// todo: SiteOptions.AuthenticationType check
if (!userDTO.isEnabled()) {
// send validation email
fmMailService.sendUserVerificationMail(user);
redirectAttributes.addFlashAttribute("statusMessage", webUI.getMessage(USER_VERIFICATION_EMAIL_SENT, user.getEmail()));
redirectionUrl += "register?message";
} else {
// non-email validation
SignInUtils.authorizeUser(user);
}
return redirectionUrl;
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class UserController method signup.
@RequestMapping(value = "/signup", method = POST)
public String signup(@Valid @ModelAttribute("socialUserDTO") SocialUserDTO socialUserDTO, BindingResult result, WebRequest request, RedirectAttributes redirectAttributes) {
if (webUI.isNixMash()) {
return "redirect:/";
}
if (result.hasErrors()) {
return SIGNUP_VIEW;
}
UserDTO userDTO = createUserDTO(socialUserDTO);
User user = userService.create(userDTO);
providerSignInUtils.doPostSignUp(userDTO.getUsername(), request);
UserConnection userConnection = userService.getUserConnectionByUserId(userDTO.getUsername());
if (userConnection.getImageUrl() != null) {
try {
webUI.processProfileImage(userConnection.getImageUrl(), user.getUserKey());
userService.updateHasAvatar(user.getId(), true);
} catch (IOException e) {
logger.error("ImageUrl IOException for username: {0}", user.getUsername());
}
}
SignInUtils.authorizeUser(user);
redirectAttributes.addFlashAttribute("connectionWelcomeMessage", true);
return "redirect:/";
}
Aggregations