X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfileFieldPage.java;h=bbc6d6b00d8f2df0299a14b9fa4d8ea09d81d6dd;hp=219bdc52253962c087e691bc9856981d4414975e;hb=9acbc5bdec4ccb752e0856a501568b0bb6161579;hpb=13e00a0611cd80e43f813171d8b6d84870afbcbc diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java index 219bdc5..bbc6d6b 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java @@ -1,5 +1,5 @@ /* - * Sone - EditProfileFieldPage.java - Copyright © 2011 David Roden + * Sone - EditProfileFieldPage.java - Copyright © 2011–2016 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user edit the name of a profile field. @@ -51,8 +52,7 @@ public class EditProfileFieldPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { - super.processTemplate(request, templateContext); + protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException { Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); @@ -75,12 +75,15 @@ public class EditProfileFieldPage extends SoneTemplatePage { } String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256); Field existingField = profile.getFieldByName(name); - if ((existingField == null) || (existingField.equals(field))) { - field.setName(name); - currentSone.setProfile(profile); + if ((existingField != null) && (!field.equals(existingField))) { + templateContext.set("duplicateFieldName", true); + } else { + if (!name.equals(field.getName())) { + field.setName(name); + currentSone.setProfile(profile); + } throw new RedirectException("editProfile.html#profile-fields"); } - templateContext.set("duplicateFieldName", true); } /* store current values in template. */