Implement profile editing.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 06:26:01 +0000 (08:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 06:26:01 +0000 (08:26 +0200)
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/editProfile.html

index ed3fb23..a646746 100644 (file)
@@ -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);
index 7d8067d..49660cd 100644 (file)
@@ -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
index d39d859..85a5e74 100644 (file)
@@ -5,24 +5,28 @@
        <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>