PortletMode curMode = actionRequest.getPortletMode();
if (curMode == PortletMode.EDIT ||
curMode.equals(JetspeedActions.EDIT_DEFAULTS_MODE))
{
PortletPreferences prefs = actionRequest.getPreferences();
PreferencesHelper.requestParamsToPreferences(actionRequest);
prefs.store();
actionResponse.setPortletMode(PortletMode.VIEW);
return;
}
try
{
for (int i = 0; i < formKeys.length; i++)
{
try
{
String key = (String) formKeys[i][0];
Boolean isRequired = (Boolean) formKeys[i][1];
String value = actionRequest.getParameter(key);
if ((value != null) && (value.length() > 0))
{
userInfo.put(key, value);
// do some validation
if (!validateFormValue(value, (Integer) formKeys[i][2],
(Integer) formKeys[i][3]))
{
errors.add(resource
.getString("error.invalid-format." + key));
}
if (key.startsWith("user."))
{
value = convertIfNeed(key, value);
// we'll assume that these map back to PLT.D values
userAttributes.put(key, value);
}
} else
{
// don't have that value or it's too short... is it
// required ?
if (isRequired.booleanValue())
{
errors.add(resource.getString("error.lacking."
+ key));
}
// place an empty version in userInfo anyway
// so that the template will display the correct fields
userInfo.put(key, "");
}
} catch (MissingResourceException mre)
{
errors.add(resource.getString("error.failed_to_add")
+ mre.toString());
}
}
// publish the whole map so we can reload the form values on error.
publishRenderMessage(actionRequest, MSG_USERINFO, userInfo);
// These next checks may duplicate previous checks.
// however this is a double check given the nature of the values and
// how they are used.
if (this.optionForceEmailAsUsername)
{
// email is something special
if (!ValidationHelper.isEmailAddress((String) userInfo
.get(USER_ATTRIBUTE_EMAIL), true, 80))
{
errors.add(resource.getString("error.invalid-format."
+ USER_ATTRIBUTE_EMAIL));
}
} else
{
if (!ValidationHelper.isAny((String) userInfo.get("user.name"),
true, 80))
{
errors.add(resource.getString("error.lacking.user.name"));
}
}
// if we're not generating make sure it's real
if (!this.optionForceGeneratedPasswords)
{
if (!ValidationHelper.isAny((String) userInfo.get("password"),
true, 25))
{
errors.add(resource.getString("error.lacking.password"));
}
}
if (optionForceEmailAsUsername)
{
// force user.name to be same as email
userInfo.put("user.name", userInfo.get(USER_ATTRIBUTE_EMAIL));
}
boolean userIdExistsFlag = true;
try
{
userManager.getUser((String) userInfo.get("user.name"));
} catch (SecurityException e)
{
userIdExistsFlag = false;
}
//
if (userIdExistsFlag)
{
errors.add(resource.getString("error.userid_already_exists"));
publishRenderMessage(actionRequest, MSG_MESSAGE, errors);
return;
}
if (optionForceEmailsToBeSystemUnique)
{
boolean emailExistsFlag = true;
User user = null;
try
{
user = admin.lookupUserFromEmail((String) userInfo
.get(USER_ATTRIBUTE_EMAIL));
} catch (AdministrationEmailException e1)
{
emailExistsFlag = false;
}
if ((emailExistsFlag) || (user != null))
{
errors
.add(resource
.getString("error.email_already_exists"));
publishRenderMessage(actionRequest, MSG_MESSAGE, errors);
return;
}
}
try
{
if (optionForceGeneratedPasswords)
{
String password = admin.generatePassword();
userInfo.put("password", password);
} else
{
if (userInfo.get("password").equals(
userInfo.get("verifyPassword")))
{
} else
{
errors.add(resource
.getString("error.two_passwords_do_not_match"));
publishRenderMessage(actionRequest, MSG_MESSAGE, errors);
return;
}
}
} catch (Exception e)
{
errors.add(resource.getString("error.failed_to_add")
+ e.toString());
publishRenderMessage(actionRequest, MSG_MESSAGE, errors);
}
// make sure no errors have occurred
if (errors.size() > 0)
{
publishRenderMessage(actionRequest, MSG_MESSAGE, errors);
return;
}
// Ok, we think we're good to go, let's create the user!
try
{
PortletPreferences prefs = actionRequest.getPreferences();
String template = prefs.getValue("newUserTemplateDirectory", "");
if (template.trim().length() == 0)
template = null;
String subsiteRootFolder = prefs.getValue("subsiteRootFolder", "");
if (subsiteRootFolder.trim().length() == 0)
subsiteRootFolder = null;
List prefRoles = getPreferencesList(prefs, IP_ROLES);
if (prefRoles.isEmpty())
prefRoles = this.roles;
List prefGroups = getPreferencesList(prefs, IP_GROUPS);
if (prefGroups.isEmpty())
prefGroups = this.groups;
List names = getPreferencesList(prefs, IP_RULES_NAMES);
List values = getPreferencesList(prefs, IP_RULES_VALUES);
Map profileRules = new HashMap();
for (int ix = 0; ix < ((names.size() < values.size()) ? names.size()
: values.size()); ix++)
{
profileRules.put(names.get(ix), values.get(ix));
}
if (profileRules.isEmpty())
profileRules = this.rules;
admin.registerUser((String) userInfo.get("user.name"),
(String) userInfo.get("password"), prefRoles,
prefGroups, userAttributes, // note use of only
// PLT.D values here.
profileRules, template, subsiteRootFolder,
actionRequest.getLocale(), actionRequest.getServerName());
String urlGUID = ForgottenPasswordPortlet.makeGUID(
(String) userInfo.get("user.name"), (String) userInfo
.get("password"));
userInfo.put(CTX_RETURN_URL, generateReturnURL(actionRequest,
actionResponse, urlGUID));
String templ = getTemplatePath(actionRequest, actionResponse);
if (templ == null) { throw new Exception(
"email template not available"); }
boolean sendEmail = prefs.getValue("SendEmail", "true").equals("true");
if (sendEmail)
{
admin.sendEmail(getPortletConfig(), (String) userInfo
.get(USER_ATTRIBUTE_EMAIL),
getEmailSubject(actionRequest), templ, userInfo);