Package eu.semberal.reminders.entity

Examples of eu.semberal.reminders.entity.User


    @Override
    public void addAttachment(InputStream stream, String filename, Long userId) throws Exception {
        if (stream == null || filename == null || userId == null)
            throw new IllegalArgumentException("Argument is null"); //if sth is null, throw exception
        User u = entityManager.find(User.class, userId);
        if (u == null)
            throw new IllegalArgumentException("User with specified ID was not found."); //if user not found, throw error

        Attachment a = new Attachment();
        a.setDateAdded(new Date());
View Full Code Here


        if (getUser(email) != null) throw new EmailAlreadyTakenException("There's an user with this email");

        String randomPass = RandomStringUtils.randomAlphanumeric(new Random().nextInt(8) + 6);
        String encodedPass = encoderService.encodeString(randomPass);

        User u = new User();
        u.setEmail(email);
        u.setPassword(encodedPass);
        u.setDateRegistered(new Date());
        u.getRoles().add("user");
        entityManager.persist(u);
        mailService.sendEmailActivation(email, randomPass);
        return u;
    }
View Full Code Here

        Query q = entityManager.createQuery("select u from User u where u.email=:email and u.password=:password");
        q.setParameter("password", encodedPassword);
        q.setParameter("email", email);
        try {

            User u = (User) q.getSingleResult();
            if (isLogin) {
                u.setLastLogin(new Date());
                entityManager.merge(u);
            }
            return u;
        } catch (NoResultException e) {
            throw new InvalidCredentialsException("Login attempt unsuccessful");
View Full Code Here

        try {
            userId=(Long)q.getSingleResult();
        } catch (NoResultException e) {
            throw new UserNotFoundException("User with this email has not been found");
        }
        User user = entityManager.find(User.class, userId);
        String randomPass = RandomStringUtils.randomAlphanumeric(new Random().nextInt(8) + 6);
        String encodedPass = encoderService.encodeString(randomPass);
        user.setPassword(encodedPass);
        if (sendEmailNotification) {
            mailService.sentPasswordReset(email, randomPass);
        }
    }
View Full Code Here

        Query q = entityManager.createQuery("select u from User u where u.lastLogin is null");
        return q.getResultList();
    }

    public void deleteUser(Long id) throws UserNotFoundException {
        User u = entityManager.find(User.class, id);
        if (u == null) throw new UserNotFoundException("User has not been found.");
        entityManager.remove(u);
    }
View Full Code Here

        return ((CustomActionBeanContext) (bean.getContext())).isAuthenticated();
    }

    @Override
    protected Boolean hasRole(ActionBean bean, Method handler, String role) {
        User u = ((CustomActionBeanContext) (bean.getContext())).getUser();
        if (u != null) {
            return u.getRoles() != null && u.getRoles().contains(role);
        }
        return false;
    }
View Full Code Here

        return new ForwardResolution("/WEB-INF/pages/login.jsp");
    }
   
    public Resolution login() {
        try {
            User u = adminService.authenticateUser(email, password, true);
            getContext().setUser(u);
            return new RedirectResolution(DashboardActionBean.class);
        } catch (InvalidCredentialsException e) {
            getContext().getRequest().setAttribute("loginFailed", true);
            return new ForwardResolution("/WEB-INF/pages/login.jsp");
View Full Code Here

TOP

Related Classes of eu.semberal.reminders.entity.User

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.