Package org.apache.struts.apps.mailreader.dao

Examples of org.apache.struts.apps.mailreader.dao.UserDatabase


        final String LOG_DATABASE_SAVE_ERROR =
                " Unexpected error when saving User: ";

        try {
            UserDatabase database = doGetUserDatabase();
            database.save();
        } catch (Exception e) {
            String message = LOG_DATABASE_SAVE_ERROR + user.getUsername();
            log.error(message, e);
            throw new ServletException(message, e);
        }
View Full Code Here


        if (resources == null) {
            messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
        }

        // Confirm database loaded
        UserDatabase userDatabase = doGetUserDatabase();
        if (userDatabase == null) {
            messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
        }

        // If there were errors, forward to our failure page
View Full Code Here

        if (log.isTraceEnabled()) {
            log.trace(" Perform additional validations on Create");
        }

        UserDatabase database = doGetUserDatabase();
        String username = doGet(form, USERNAME);
        try {
            if (database.findUser(username) != null) {
                errorUsernameUnique(username, errors);
            }
        }
        catch (ExpiredPasswordException e) {
            errorUsernameUnique(username, errors);
            errors.add("errors.literal", new ActionMessage(e.getMessage()));
        }

        String password = doGet(form, PASSWORD);
        if ((password == null) || (password.length() < 1)) {
            errors.add(PASSWORD, new ActionMessage("error.password.required"));

            String password2 = doGet(form, PASSWORD2);
            if ((password2 == null) || (password2.length() < 1)) {
                errors.add(
                        PASSWORD2,
                        new ActionMessage("error.password2.required"));
            }
        }

        if (!errors.isEmpty()) {
            return null;
        }

        User user = database.createUser(username);

        // Log the user in
        HttpSession session = request.getSession();
        session.setAttribute(Constants.USER_KEY, user);
        if (log.isTraceEnabled()) {
View Full Code Here

     * @return A new User and empty Errors if create succeeds, or null and
     *         Errors if create fails
     */
    public User createUser(String username, String password) {

        UserDatabase database = getDatabase();
        User user;

        try {
            user = database.findUser(username);
         }

        catch (ExpiredPasswordException e) {
            user = getUser(); // Just so that it is not null
        }

        if (user != null) {
            this.addFieldError("username", "error.username.unique");
            return null;
        }

        return database.createUser(username);
    }
View Full Code Here

        if (resources == null) {
            messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
        }

        // Confirm database loaded
        UserDatabase userDatabase = doGetUserDatabase();
        if (userDatabase == null) {
            messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
        }

        // If there were errors, forward to our failure page
View Full Code Here

        if (log.isTraceEnabled()) {
            log.trace(" Perform additional validations on Create");
        }

        UserDatabase database = doGetUserDatabase();
        String username = doGet(form, USERNAME);
        try {
            if (database.findUser(username) != null) {
                errorUsernameUnique(username, errors);
            }
        }
        catch (ExpiredPasswordException e) {
            errorUsernameUnique(username, errors);
            errors.add("errors.literal", new ActionMessage(e.getMessage()));
        }

        String password = doGet(form, PASSWORD);
        if ((password == null) || (password.length() < 1)) {
            errors.add(PASSWORD, new ActionMessage("error.password.required"));

            String password2 = doGet(form, PASSWORD2);
            if ((password2 == null) || (password2.length() < 1)) {
                errors.add(
                        PASSWORD2,
                        new ActionMessage("error.password2.required"));
            }
        }

        if (!errors.isEmpty()) {
            return null;
        }

        User user = database.createUser(username);

        // Log the user in
        HttpSession session = request.getSession();
        session.setAttribute(Constants.USER_KEY, user);
        if (log.isTraceEnabled()) {
View Full Code Here

        final String LOG_DATABASE_SAVE_ERROR =
                " Unexpected error when saving User: ";

        try {
            UserDatabase database = doGetUserDatabase();
            database.save();
        } catch (Exception e) {
            String message = LOG_DATABASE_SAVE_ERROR + user.getUsername();
            log.error(message, e);
            throw new ServletException(message, e);
        }
View Full Code Here

     * @return A new User and empty Errors if create succeeds, or null and
     *         Errors if create fails
     */
    public User createUser(String username, String password) {

        UserDatabase database = getDatabase();
        User user;

        try {
            user = database.findUser(username);
         }

        catch (ExpiredPasswordException e) {
            user = getUser(); // Just so that it is not null
        }

        if (user != null) {
            this.addFieldError("username", "error.username.unique");
            return null;
        }

        return database.createUser(username);
    }
View Full Code Here

     * @return A new User and empty Errors if create succeeds, or null and
     *         Errors if create fails
     */
    public User createUser(String username, String password) {

        UserDatabase database = getDatabase();
        User user;

        try {
            user = database.findUser(username);
         }

        catch (ExpiredPasswordException e) {
            user = getUser(); // Just so that it is not null
        }

        if (user != null) {
            this.addFieldError("username", "error.username.unique");
            return null;
        }

        return database.createUser(username);
    }
View Full Code Here

     * <p>Create or update the user information.</p>
     */
    public String save() {

        State state = getState();
        UserDatabase database = getUserDatabase();
        String mode = state.getMode();
        User user = state.getUser();
        org.apache.struts.apps.mailreader.dao.Subscription subscription =
                user.findSubscription(state.getHost());

        if ("CREATE".equals(mode)) {

            // Verify that the proposed hostname is not already taken
            if (user.findSubscription(host) != null) {
                // FIXME - localization
                getFacesContext().addMessage("subscription:host",
                        new FacesMessage("That hostname is already defined"));
                return null;
            }

            // Create a new subscription
            subscription = user.createSubscription(host);
            Registration registration = (Registration)getBean("registration");
            user = getState().getUser();
            registration.setFromAddress(user.getFromAddress());
            registration.setFullName(user.getFullName());
            registration.setPassword(user.getPassword());
            registration.setPassword2(user.getPassword());
            registration.setReplyToAddress(user.getReplyToAddress());
            registration.setSubscriptions(user.getSubscriptions());
            registration.setUsername(user.getUsername());

        } else if ("DELETE".equals(mode)) {

            user.removeSubscription(subscription);
            try {
                database.save();
            } catch (Exception e) {
                getFacesContext().addMessage(null,
                        new FacesMessage(e.getMessage()));
                log.error("Database save exception", e);
                return null;
            }
            state.setMode("EDIT");
            return "registration";

        } else /* if ("EDIT".equals(mode)) */ {

            ; // No special action required

        }

        // Copy the remaining properties
        subscription.setUsername(username);
        subscription.setPassword(password);
        subscription.setType(type);
        subscription.setAutoConnect(autoConnect);

        // Save the updated information to the database
        try {
            database.save();
        } catch (Exception e) {
            getFacesContext().addMessage(null,
                    new FacesMessage(e.getMessage()));
            log.error("Database save exception", e);
            return null;
View Full Code Here

TOP

Related Classes of org.apache.struts.apps.mailreader.dao.UserDatabase

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.