Package org.jtalks.jcommune.model.entity

Examples of org.jtalks.jcommune.model.entity.JCUser


     * @return the copy of user currently logged in or {@link AnonymousUser} if user is anonymous
     * @see AnonymousUser
     */
    @Override
    public JCUser getCurrentUser() {
        JCUser currentUser = userReader.getCurrentUser();
        if (currentUser.isAnonymous()) {
            return new AnonymousUser();
        } else {
            return JCUser.copyUser(currentUser);
        }
    }
View Full Code Here


    }

    @Test
    public void testActivateAccount() throws Exception {

        JCUser user = new JCUser("username", "password", null);
        user.setPassword("password");
        when(userService.getByUuid(USER_NAME)).thenReturn(user);
        String viewName = userController.activateAccount(USER_NAME, request, response);
        verify(userService, times(1)).activateAccount(USER_NAME);
        verify(userService, times(1)).loginUser(any(LoginUserDto.class), any(MutableHttpRequest.class), eq(response));
        assertEquals("redirect:/", viewName);
View Full Code Here

    }

    @Test
    public void testActivateAccountAgain() throws Exception {

        JCUser user = new JCUser("username", "password", null);
        user.setEnabled(true);
        when(userService.getByUuid(USER_NAME)).thenReturn(user);
        doThrow(new UserTriesActivatingAccountAgainException()).when(userService).activateAccount(anyString());

        String viewName = userController.activateAccount(USER_NAME, request, response);
        assertEquals("redirect:/", viewName);
View Full Code Here

        assertEquals("redirect:/", viewName);
    }

    @Test(dataProvider = "referers")
    public void testLoginUserLogged(String referer) {
        when(userService.getCurrentUser()).thenReturn(new JCUser("username", null, null));
        when(request.getHeader("referer")).thenReturn(referer);

        ModelAndView mav = userController.loginPage(request);

        assertEquals(mav.getViewName(), "redirect:" + referer);
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isValid(UserSecurityDto dto, ConstraintValidatorContext context) {
        JCUser currentUser = userService.getCurrentUser();
        String editedUserName = getUsername(dto.getUserId());
        String currentUserName = currentUser.getUsername();
        boolean isWillBeChangedByOwner = ObjectUtils.equals(editedUserName, currentUserName);
        if (isWillBeChangedByOwner) {
            boolean result = dto.getNewUserPassword() == null;
            //we must compare the hashes, so we encrypt the entered value
            String enteredCurrentPassword = encryptionService.encryptPassword(dto.getCurrentUserPassword());
            result |= currentUser.getPassword().equals(enteredCurrentPassword);
            if (!result) {
                // add validation error to the field
                context.buildConstraintViolationWithTemplate(message)
                        .addNode("currentUserPassword")
                        .addConstraintViolation();
View Full Code Here

     * @param userId user's id
     * @return an username
     */
    private String getUsername(long userId) {
        try {
            JCUser user = userService.get(userId);
            return user.getUsername();
        } catch (NotFoundException e) {
            return null;
        }
    }
View Full Code Here

        dto.setRecipient(USERNAME);
        return dto;
    }

    private PrivateMessage getPrivateMessage() {
        return new PrivateMessage(new JCUser("username", "email", "password"),
                new JCUser("username2", "email2", "password2"), "title", "body");
    }
View Full Code Here

     * @param userId user's id
     * @return an email of user by user's id
     */
    private String getEmailOfUser(long userId) {
        try {
            JCUser user = userService.get(userId);
            return user.getEmail();
        } catch (NotFoundException e) {
            return null;
       
    }
View Full Code Here

     * @param context validator context, not used here
     * @return true if user specified is not the current one logged in
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        JCUser user = service.getCurrentUser();
        return user.isAnonymous() || !user.getUsername().equalsIgnoreCase(value);
    }
View Full Code Here

        Locale locale = (Locale)request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
        if (locale != null) {
            return locale;
        }

        JCUser currentUser = userService.getCurrentUser();
        if (currentUser.isAnonymous()) {
            locale = super.resolveLocale(request);
        } else {
            locale = currentUser.getLanguage().getLocale();
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME, locale);
        return locale;
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.model.entity.JCUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.