*/
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
ToadletContext toadletContenxt = request.getToadletContext();
Sone currentSone = getCurrentSone(toadletContenxt);
Profile profile = currentSone.getProfile();
String firstName = profile.getFirstName();
String middleName = profile.getMiddleName();
String lastName = profile.getLastName();
Integer birthDay = profile.getBirthDay();
Integer birthMonth = profile.getBirthMonth();
Integer birthYear = profile.getBirthYear();
String avatarId = profile.getAvatar();
List<Field> fields = profile.getFields();
if (request.getMethod() == Method.POST) {
if (request.getHttpRequest().getPartAsStringFailsafe("save-profile", 4).equals("true")) {
firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
birthDay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim());
birthMonth = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim());
birthYear = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim());
avatarId = request.getHttpRequest().getPartAsStringFailsafe("avatarId", 36);
profile.setFirstName(firstName.length() > 0 ? firstName : null);
profile.setMiddleName(middleName.length() > 0 ? middleName : null);
profile.setLastName(lastName.length() > 0 ? lastName : null);
profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
profile.setAvatar(webInterface.getCore().getImage(avatarId, false));
for (Field field : fields) {
String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + field.getId(), 400);
String filteredValue = filter(request.getHttpRequest().getHeader("Host"), value);
field.setValue(filteredValue);
}
currentSone.setProfile(profile);
webInterface.getCore().touchConfiguration();
throw new RedirectException("editProfile.html");
} else if (request.getHttpRequest().getPartAsStringFailsafe("add-field", 4).equals("true")) {
String fieldName = request.getHttpRequest().getPartAsStringFailsafe("field-name", 256).trim();
try {
profile.addField(fieldName);
currentSone.setProfile(profile);
fields = profile.getFields();
webInterface.getCore().touchConfiguration();
throw new RedirectException("editProfile.html#profile-fields");
} catch (IllegalArgumentException iae1) {
templateContext.set("fieldName", fieldName);
templateContext.set("duplicateFieldName", true);
}
} else {
String id = getFieldId(request, "delete-field-");
if (id != null) {
throw new RedirectException("deleteProfileField.html?field=" + id);
}
id = getFieldId(request, "move-up-field-");
if (id != null) {
Field field = profile.getFieldById(id);
if (field == null) {
throw new RedirectException("invalid.html");
}
profile.moveFieldUp(field);
currentSone.setProfile(profile);
throw new RedirectException("editProfile.html#profile-fields");
}
id = getFieldId(request, "move-down-field-");
if (id != null) {
Field field = profile.getFieldById(id);
if (field == null) {
throw new RedirectException("invalid.html");
}
profile.moveFieldDown(field);
currentSone.setProfile(profile);
throw new RedirectException("editProfile.html#profile-fields");
}
id = getFieldId(request, "edit-field-");
if (id != null) {
throw new RedirectException("editProfileField.html?field=" + id);