From 4c8a0c10d45005c0a7e55aeff8534ae652c1a0e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 14 Oct 2010 08:26:01 +0200 Subject: [PATCH] Implement profile editing. --- .../net/pterodactylus/sone/web/EditProfilePage.java | 17 ++++++++++++++++- src/main/resources/i18n/sone.en.properties | 1 + src/main/resources/templates/editProfile.html | 12 ++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) 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> +
- +
- +
- +
- +
-- 2.7.4