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

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


     * @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>
     * @throws ExpiredPasswordException
     */
    public String save() throws ExpiredPasswordException {

        UserDatabase database = getUserDatabase();
        String mode = getState().getMode();
        boolean ok = true;
        User user = null;

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

            // Verify that the proposed username is not already taken
            if (database.findUser(username) != null) {
                // FIXME - localization
                getFacesContext().addMessage("registration:username",
                  new FacesMessage("That username is already taken"));
                ok = false;
            }

            // Verify that the two password values match
            if (!password.equals(password2)) {
                // FIXME - localization
                getFacesContext().addMessage("registration:password2",
                  new FacesMessage("Password values do not match"));
                ok = false;
            }

            // Create a new user with the specified username and password
            // and log the new user on
            if (ok) {
                user = database.createUser(username);
                getState().setUser(user);
            }
           

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

            // Verify that the two password values match (if entered)
            if ((password != null) && (password.length() > 0) &&
                (password2 != null) && (password2.length() > 0) &&
                !password.equals(password2)) {
                // FIXME - localization
                getFacesContext().addMessage("registration:password2",
                  new FacesMessage("Password values do not match"));
                ok = false;
            }

            // Edit the currently logged on user
            user = getState().getUser();

        }
       
        // Copy the remaining properties
        if (ok) {
            if ((password != null) && (password.length() > 0)) {
                user.setPassword(password);
            }
            user.setFullName(fullName);
            user.setFromAddress(fromAddress);
            user.setReplyToAddress(replyToAddress);
        }

        // 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);
            ok = false;
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.