FileDocCategorySizeDatePackage
Registration.javaAPI DocApache Struts 2.0.9 Apps3821Mon Jul 23 13:43:12 BST 2007mailreader2

Registration

public class Registration extends MailreaderSupport

Insert or update a User object to the persistent store.

Fields Summary
Constructors Summary
Methods Summary
public java.lang.Stringexecute()

Insert or update a User object to the persistent store.

If a User is not logged in, then a new User is created and automatically logged in. Otherwise, the existing User is updated.

return
The "outcome" result code
throws
Exception on any error


        boolean creating = Constants.CREATE.equals(getTask());
        creating = creating && isCreating(); // trust but verify

        if (creating) {

            User user = findUser(getUsername(), getPassword());
            boolean haveUser = (user != null);

            if (haveUser) {
                addActionError(getText("error.username.unique"));
                return INPUT;
            }

            copyUser(getUsername(), getPassword());

        } else {

            // FIXME: Any way to call the RegisrationSave validators from here?
            String newPassword = getPassword();
            if (newPassword != null) {
                String confirmPassword = getPassword2();
                boolean matches = ((null != confirmPassword)
                        && (confirmPassword.equals(newPassword)));
                if (matches) {
                    getUser().setPassword(newPassword);
                } else {
                    addActionError(getText("error.password.match"));
                    return INPUT;
                }
            }
        }

        saveUser();

        return SUCCESS;
    
public java.lang.Stringinput()

Retrieve User object to edit or null if User does not exist.

return
The "Success" result for this mapping
throws
Exception on any error


        if (isCreating()) {
            createInputUser();
            setTask(Constants.CREATE);
        } else {
            setTask(Constants.EDIT);
            setUsername(getUser().getUsername());
            setPassword(getUser().getPassword());
            setPassword2(getUser().getPassword());
        }

        return INPUT;
    
private booleanisCreating()

Double check that there is not a valid User login.

return
True if there is not a valid User login

        User user = getUser();
        return (null == user) || (null == user.getDatabase());
    
public java.lang.Stringsave()

Insert or update a Registration.

return
The "outcome" result code
throws
Exception on any error

        return execute();