use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class UserPasswordController method sendForgotEmail.
@RequestMapping(value = "/users/forgotpassword", method = POST)
public String sendForgotEmail(@Valid ForgotEmailDTO forgotEmailDTO, BindingResult result, Model model) {
if (result.hasErrors()) {
return USER_FORGOTPASSWORD_VIEW;
} else {
Optional<User> user = userService.getByEmail(forgotEmailDTO.getEmail());
if (!user.isPresent()) {
result.reject("global.error.email.does.not.exist");
} else {
model.addAttribute(FLASH_MESSAGE_KEY_FEEDBACK, webUI.getMessage(FEEDBACK_PASSWORD_EMAIL_SENT));
model.addAttribute("forgotEmailDTO", new ForgotEmailDTO());
UserToken userToken = userService.createUserToken(user.get());
fmMailService.sendResetPasswordMail(user.get(), userToken.getToken());
}
}
return USER_FORGOTPASSWORD_VIEW;
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class CustomAuthenticationFailureHandler method onAuthenticationFailure.
@Override
public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException exception) throws IOException, ServletException {
setDefaultFailureUrl("/signin?error");
super.onAuthenticationFailure(request, response, exception);
String errorMessage = webUI.getMessage(GENERIC_AUTHENTICATION_ERROR_KEY);
User user = userService.getUserByUsername(request.getParameter(USERNAME));
if (user != null) {
String notYetApprovedMessage = webUI.getMessage(NOT_YET_USER_VERIFIED_ERROR_KEY, user.getUsername(), user.getEmail());
if (exception.getMessage().equalsIgnoreCase((USER_IS_DISABLED))) {
if (user.getUserData().getApprovedDatetime() == null)
errorMessage = notYetApprovedMessage;
}
}
request.getSession().setAttribute(WebAttributes.AUTHENTICATION_EXCEPTION, errorMessage);
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class AdminController method addUser.
@RequestMapping(value = "/users/new", method = RequestMethod.POST)
public String addUser(@Valid UserDTO userDTO, BindingResult result, SessionStatus status, Model model, RedirectAttributes attributes) {
if (result.hasErrors()) {
model.addAttribute("authorities", userService.getRoles());
return ADMIN_USERFORM_VIEW;
} else {
userDTO.setSignInProvider(SignInProvider.SITE);
User added = userService.create(userDTO);
logger.info("Added user with information: {}", added);
status.setComplete();
webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_USER_ADDED, added.getFirstName(), added.getLastName());
return "redirect:/admin/users";
}
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class AdminController method populateUserForm.
private ModelAndView populateUserForm(Long id) {
ModelAndView mav = new ModelAndView();
Optional<User> found = userService.getUserById(id);
User user;
if (found.isPresent()) {
user = found.get();
logger.info("Editing User with id and username: {} {}", id, user.getUsername());
mav.addObject("userDTO", UserUtils.userToUserDTO(user));
} else {
mav.addObject("userDTO", new UserDTO());
}
mav.addObject("authorities", userService.getRoles());
mav.setViewName(ADMIN_USERFORM_VIEW);
return mav;
}
use of com.nixmash.blog.jpa.model.User in project nixmash-blog by mintster.
the class UserRegistrationTests method newUser_AfterEmailVerification_IsEnabled.
@Test
public void newUser_AfterEmailVerification_IsEnabled() throws Exception {
UserDTO userDTO = UserTestUtils.newUserDTO(56, NOT_ENABLED);
User user = userService.enableAndApproveUser(userService.create(userDTO));
assertTrue(user.isEnabled());
assertNotNull(user.getUserData().getApprovedDatetime());
}
Aggregations