Search in sources :

Example 6 with User

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

Example 7 with User

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));
    }
}
Also used : User(com.nixmash.blog.jpa.model.User) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.junit.Test)

Example 8 with User

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

Example 9 with User

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

Example 10 with User

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:/";
}
Also used : User(com.nixmash.blog.jpa.model.User) SocialUserDTO(com.nixmash.blog.jpa.dto.SocialUserDTO) UserDTO(com.nixmash.blog.jpa.dto.UserDTO) IOException(java.io.IOException) UserConnection(com.nixmash.blog.jpa.model.UserConnection)

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