// run some validation
myValidate();
if (!hasActionErrors()) try {
UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
// copy form data into new user pojo
User newUser = new User();
getBean().copyTo(newUser, getLocale()); // doesn't copy password
newUser.setDateCreated(new java.util.Date());
// set username and password
newUser.setUserName(getBean().getUserName());
newUser.resetPassword(getBean().getPassword());
// are we granting the user admin rights?
if(((CreateUserBean)getBean()).isAdministrator()) {
newUser.grantRole("admin");
}
// save new user
mgr.addUser(newUser);
WebloggerFactory.getWeblogger().flush();
// TODO: i18n
addMessage("New user created");