package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.template.Template;
import freenet.clients.http.ToadletContext;
protected void processTemplate(Request request, Template template) throws RedirectException {
super.processTemplate(request, template);
ToadletContext toadletContenxt = request.getToadletContext();
- Profile profile = getCurrentSone(toadletContenxt).getProfile();
+ Sone currentSone = getCurrentSone(toadletContenxt);
+ Profile profile = currentSone.getProfile();
String firstName = profile.getFirstName();
String middleName = profile.getMiddleName();
String lastName = profile.getLastName();
+ if (request.getMethod() == Method.POST) {
+ firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
+ middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
+ lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
+ profile.setFirstName(firstName.length() > 0 ? firstName : null);
+ profile.setMiddleName(middleName.length() > 0 ? middleName : null);
+ profile.setLastName(lastName.length() > 0 ? lastName : null);
+ if (profile.isModified()) {
+ currentSone.setProfile(profile);
+ }
+ template.set("changed", true);
+ }
template.set("firstName", firstName);
template.set("middleName", middleName);
template.set("lastName", lastName);
<div><%= Page.EditProfile.Page.Description|l10n|html></div>
<div><%= Page.EditProfile.Page.Hint.Optionality|l10n|html></div>
+ <%if changed>
+ <div><%= Page.EditProfile.Page.Status.Changed|l10n|html></div>
+ <%/if>
+
<form method="post">
<input type="hidden" name="formPassword" value="<% formPassword|html>" />
-
+
<div>
<label for="first-name"><%= Page.EditProfile.Label.FirstName|l10n|html></label>
<input type="text" name="first-name" value="<% firstName|html>" />
</div>
-
+
<div>
<label for="middle-name"><%= Page.EditProfile.Label.MiddleName|l10n|html></label>
<input type="text" name="middle-name" value="<% middleName|html>" />
</div>
-
+
<div>
<label for="last-name"><%= Page.EditProfile.Label.LastName|l10n|html></label>
<input type="text" name="last-name" value="<% lastName|html>" />
</div>
-
+
</form>
</div>