From: David ‘Bombe’ Roden Date: Thu, 14 Oct 2010 06:26:01 +0000 (+0200) Subject: Implement profile editing. X-Git-Tag: 0.1-RC1~434 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4c8a0c10d45005c0a7e55aeff8534ae652c1a0e2;p=Sone.git Implement profile editing. --- diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java index ed3fb23..a646746 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java @@ -18,6 +18,8 @@ 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; @@ -51,10 +53,23 @@ public class EditProfilePage extends SoneTemplatePage { 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); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 7d8067d..49660cd 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -51,5 +51,6 @@ Page.EditProfile.Page.Hint.Optionality=And remember, every single field of this Page.EditProfile.Label.FirstName=First name: Page.EditProfile.Label.MiddleName=Middle name(s): Page.EditProfile.Label.LastName=Last name: +Page.EditProfile.Page.Status.Changed=Your changes have been saved and will be inserted shortly. Page.Logout.Title=Logout - Sone diff --git a/src/main/resources/templates/editProfile.html b/src/main/resources/templates/editProfile.html index d39d859..85a5e74 100644 --- a/src/main/resources/templates/editProfile.html +++ b/src/main/resources/templates/editProfile.html @@ -5,24 +5,28 @@
<%= Page.EditProfile.Page.Description|l10n|html>
<%= Page.EditProfile.Page.Hint.Optionality|l10n|html>
+ <%if changed> +
<%= Page.EditProfile.Page.Status.Changed|l10n|html>
+ <%/if> +
- +
- +
- +
- +