Mercurial Hosting > nabble
view src/nabble/view/web/user/EditProfile.jtp @ 62:4674ed7d56df default tip
remove n2
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 30 Sep 2023 20:25:29 -0600 |
parents | 18cf4872fd7f |
children |
line wrap: on
line source
<% package nabble.view.web.user; import fschmidt.db.DbDatabase; import fschmidt.util.java.HtmlUtils; import fschmidt.util.servlet.ServletUtils; import nabble.model.Db; import nabble.model.ModelException; import nabble.model.User; import nabble.view.lib.Jtp; import nabble.view.lib.Shared; import nabble.view.lib.help.Help; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; public final class EditProfile extends HttpServlet { protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); User user = Jtp.getUser(request); if( user==null ) { Jtp.login("You must login to edit your profile.",request,response); return; } String password1 = null; String password2 = null; String name; String errorMsg = null; if ("save".equals(request.getParameter("action")) && "POST".equals(request.getMethod())) { password1 = request.getParameter("password1"); password2 = request.getParameter("password2"); name = request.getParameter("name"); if (!password1.equals(password2) ) { errorMsg = "The password fields don't match."; } else if (password1.length() > 0 && password1.trim().length() == 0) { errorMsg = "Your password must contain valid alphanumeric characters."; } else { DbDatabase db = user.getSite().getDb(); db.beginTransaction(); try { User u = user.getGoodCopy(); if (password1.length() > 0) u.setPassword(password1); u.setName(name); u.update(); db.commitTransaction(); String pwd = u.getPasscookie(); ServletUtils.setCookie(request,response,"username", HtmlUtils.urlEncode(name), false, null); ServletUtils.setCookie(request,response,"password", HtmlUtils.urlEncode(pwd), false, null); StringBuffer js = new StringBuffer(); js.append("if (parent.nabbleinfo) {"); js.append("Nabble.setCookie('username','").append(HtmlUtils.javascriptStringEncode(HtmlUtils.urlEncode(name))).append("');"); js.append("Nabble.setCookie('password','").append(HtmlUtils.javascriptStringEncode(HtmlUtils.urlEncode(pwd))).append("');"); js.append("}"); Shared.javascriptRedirect(request,response, "/template/NamlServlet.jtp?macro=user_profile", js.toString()); return; } catch(ModelException e) { errorMsg = e.getMessage(); } finally { db.endTransaction(); } } } else { name = user.getName(); } %> <html> <head> <% Shared.title(request,response,"Edit Personal Information"); %> </head> <body> <% Shared.minHeaderGlobal(request, response); %> <% Shared.profileHeading(request,out,user,"Edit Personal Information"); %> <% Shared.errorMessage(request,response,errorMsg, "Please re-enter the information and click on \"Update Information\"."); %> <style> div.field-title { margin-top: 0; } </style> <form method=post action="EditProfile.jtp"> <input type=hidden name="action" value="save"> <div class="field-box light-border-color"> <div class="second-font field-title">Email</div> <div class="weak-color"> <%=user.getEmail()%> » <a href="ChangeEmail.jtp">Change Email</a> </div> </div> <div class="field-box light-border-color" id="username-field" > <div class="second-font field-title">Your User Name</div> <div class="weak-color"> Your user name must be unique in <%=user.getSite().getRootNode().getSubjectHtml()%>. </div> <div><input name="name" size="25" maxlength="25" value="<%=HtmlUtils.htmlEncode(Jtp.hideNull(name))%>" /></div> </div> <div class="field-box light-border-color"> <div class="second-font field-title">Change Password</div> <div class="weak-color">Nabble encrypts your password (<a href="<%=Help.password.url(request)%>">?</a>)</div> <table style="margin: .4em 0" class="shaded-bg-color"> <tr valign="top"> <td class="form-label" style="padding-top:.6em">Password: </td> <td><input type="password" name="password1" size="25" value="<%=Jtp.hideNull(password1)%>"/></td> </tr> <tr> <td class="form-label">Confirm Password: </td> <td><input type="password" name="password2" size="25" value="<%=Jtp.hideNull(password2)%>"/></td> </tr> </table> </div> <div class="field-box light-border-color" style="padding-top:0"> <input type=submit value="Update Personal Information" /> or <a href="/template/NamlServlet.jtp?macro=user_profile">Cancel</a> </div> </form> <% Shared.footer(request,response); %> <% Shared.analytics(request,response); %> </body> </html> <% } } %>