X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfilePage.java;h=1183100b9b133e7fc95af8a5a8762770cc0d3619;hb=e8ca06ebeb10e411775f3e835c14f8009c767e0d;hp=181c4542dab7d90f0fd2b8d7119dbff6a028bdd7;hpb=08ea47f96c1e0a5afa203db78ea2afeaaaea5d49;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java index 181c454..1183100 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java @@ -20,6 +20,7 @@ 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.number.Numbers; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -39,7 +40,7 @@ public class EditProfilePage extends SoneTemplatePage { * The Sone web interface */ public EditProfilePage(Template template, WebInterface webInterface) { - super("editProfile.html", template, "Page.EditProfile.Title", webInterface); + super("editProfile.html", template, "Page.EditProfile.Title", webInterface, true); } // @@ -58,33 +59,31 @@ public class EditProfilePage extends SoneTemplatePage { String firstName = profile.getFirstName(); String middleName = profile.getMiddleName(); String lastName = profile.getLastName(); + Integer birthDay = profile.getBirthDay(); + Integer birthMonth = profile.getBirthMonth(); + Integer birthYear = profile.getBirthYear(); 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()) { + if (request.getHttpRequest().getPartAsStringFailsafe("saveProfile", 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()); + 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); currentSone.setProfile(profile); + throw new RedirectException("index.html"); } - throw new RedirectException("index.html"); } template.set("firstName", firstName); template.set("middleName", middleName); template.set("lastName", lastName); - } - - // - // SONETEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected boolean requiresLogin() { - return true; + template.set("birthDay", birthDay); + template.set("birthMonth", birthMonth); + template.set("birthYear", birthYear); } }