Package org.traccar.web.shared.model

Examples of org.traccar.web.shared.model.User


        if (applicationSettings == null) {
            return getApplicationSettings();
        } else {
            EntityManager entityManager = getServletEntityManager();
            synchronized (entityManager) {
                User user = getSessionUser();
                if (user.getAdmin()) {
                    entityManager.getTransaction().begin();
                    try {
                        entityManager.merge(applicationSettings);
                        entityManager.getTransaction().commit();
                        this.applicationSettings =  applicationSettings;
View Full Code Here


                ApplicationContext.getInstance().getUserSettings(),
                new UserSettingsDialog.UserSettingsHandler() {
                    @Override
                    public void onSave(UserSettings userSettings) {
                        ApplicationContext.getInstance().setUserSettings(userSettings);
                        User user = ApplicationContext.getInstance().getUser();
                        Application.getDataService().updateUser(user, new BaseAsyncCallback<User>() {
                            @Override
                            public void onSuccess(User result) {
                                ApplicationContext.getInstance().setUser(result);
                            }
View Full Code Here

                new UsersDialog(userStore, new UsersDialog.UserHandler() {

                    @Override
                    public void onAdd() {
                        new UserDialog(
                                new User(),
                                new UserDialog.UserHandler() {
                                    @Override
                                    public void onSave(User user) {
                                        Application.getDataService().addUser(user, new BaseAsyncCallback<User>() {
                                            @Override
View Full Code Here

        // Create Administrator account
        EntityManager entityManager = getServletEntityManager();
        TypedQuery<User> query = entityManager.createQuery("SELECT x FROM User x WHERE x.login = 'admin'", User.class);
        List<User> results = query.getResultList();
        if (results.isEmpty()) {
            User user = new User();
            user.setLogin("admin");
            user.setPassword("admin");
            user.setAdmin(true);
            createUser(entityManager, user);
        }
    }
View Full Code Here

        }
    }

    private User getSessionUser() {
        HttpSession session = getThreadLocalRequest().getSession();
        User user = (User) session.getAttribute(ATTRIBUTE_USER);
        if (user == null) {
            throw new IllegalStateException();
        }
        return user;
    }
View Full Code Here

                    "SELECT x FROM User x WHERE x.login = :login", User.class);
            query.setParameter("login", login);
            List<User> results = query.getResultList();

            if (!results.isEmpty() && password.equals(results.get(0).getPassword())) {
                User user = results.get(0);
                setSessionUser(user);
                return user;
            }
            throw new IllegalStateException();
        }
View Full Code Here

                TypedQuery<User> query = entityManager.createQuery(
                        "SELECT x FROM User x WHERE x.login = :login", User.class);
                query.setParameter("login", login);
                List<User> results = query.getResultList();
                if (results.isEmpty()) {
                        User user = new User();
                        user.setLogin(login);
                        user.setPassword(password);
                        createUser(getSessionEntityManager(), user);
                        setSessionUser(user);
                        return user;               
                }
                else
View Full Code Here

        }
    }

    @Override
    public User addUser(User user) {
        User currentUser = getSessionUser();
        if (user.getLogin().isEmpty() || user.getPassword().isEmpty()) {
            throw new IllegalArgumentException();
        }
        if (currentUser.getAdmin()) {
            EntityManager entityManager = getSessionEntityManager();
            synchronized (entityManager) {
               
                String login = user.getLogin();
                TypedQuery<User> query = entityManager.createQuery("SELECT x FROM User x WHERE x.login = :login", User.class);
View Full Code Here

        }
    }

    @Override
    public User updateUser(User user) {
        User currentUser = getSessionUser();
        if (user.getLogin().isEmpty() || user.getPassword().isEmpty()) {
            throw new IllegalArgumentException();
        }
        if (currentUser.getAdmin() || (currentUser.getId() == user.getId() && !user.getAdmin())) {
            EntityManager entityManager = getSessionEntityManager();
            synchronized (entityManager) {
                entityManager.getTransaction().begin();
                try {
                    // TODO: better solution?
                    if (currentUser.getId() == user.getId()) {
                        currentUser.setLogin(user.getLogin());
                        currentUser.setPassword(user.getPassword());
                        currentUser.setUserSettings(user.getUserSettings());
                        currentUser.setAdmin(user.getAdmin());
                        entityManager.merge(currentUser);
                        user = currentUser;
                    } else {
                        // TODO: handle other users
                    }
View Full Code Here

        }
    }

    @Override
    public User removeUser(User user) {
        User currentUser = getSessionUser();
        if (currentUser.getAdmin()) {
            EntityManager entityManager = getSessionEntityManager();
            synchronized (entityManager) {
                entityManager.getTransaction().begin();
                try {
                    user = entityManager.merge(user);
View Full Code Here

TOP

Related Classes of org.traccar.web.shared.model.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.