Search in sources :

Example 11 with User

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;
}
Also used : ForgotEmailDTO(com.nixmash.blog.jpa.dto.ForgotEmailDTO) CurrentUser(com.nixmash.blog.jpa.model.CurrentUser) User(com.nixmash.blog.jpa.model.User) UserToken(com.nixmash.blog.jpa.model.UserToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with User

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);
}
Also used : User(com.nixmash.blog.jpa.model.User)

Example 13 with User

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";
    }
}
Also used : User(com.nixmash.blog.jpa.model.User)

Example 14 with User

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;
}
Also used : User(com.nixmash.blog.jpa.model.User) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 15 with User

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());
}
Also used : User(com.nixmash.blog.jpa.model.User) UserDTO(com.nixmash.blog.jpa.dto.UserDTO) Test(org.junit.Test)

Aggregations

User (com.nixmash.blog.jpa.model.User)15 Test (org.junit.Test)6 UserDTO (com.nixmash.blog.jpa.dto.UserDTO)4 Authority (com.nixmash.blog.jpa.model.Authority)2 CurrentUser (com.nixmash.blog.jpa.model.CurrentUser)2 ForgotEmailDTO (com.nixmash.blog.jpa.dto.ForgotEmailDTO)1 SocialUserDTO (com.nixmash.blog.jpa.dto.SocialUserDTO)1 UserConnection (com.nixmash.blog.jpa.model.UserConnection)1 UserToken (com.nixmash.blog.jpa.model.UserToken)1 IOException (java.io.IOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)1 ConnectionData (org.springframework.social.connect.ConnectionData)1 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1