Mercurial Hosting > nabble
comparison src/nabble/view/web/user/EditProfile.jtp @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children | 18cf4872fd7f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 <% | |
2 package nabble.view.web.user; | |
3 | |
4 import fschmidt.db.DbDatabase; | |
5 import fschmidt.util.java.HtmlUtils; | |
6 import fschmidt.util.servlet.ServletUtils; | |
7 import nabble.model.Db; | |
8 import nabble.model.ModelException; | |
9 import nabble.model.User; | |
10 import nabble.view.lib.Jtp; | |
11 import nabble.view.lib.Shared; | |
12 import nabble.view.lib.help.Help; | |
13 | |
14 import javax.servlet.ServletException; | |
15 import javax.servlet.http.HttpServlet; | |
16 import javax.servlet.http.HttpServletRequest; | |
17 import javax.servlet.http.HttpServletResponse; | |
18 import java.io.IOException; | |
19 import java.io.PrintWriter; | |
20 | |
21 | |
22 public final class EditProfile extends HttpServlet { | |
23 | |
24 protected void service(HttpServletRequest request,HttpServletResponse response) | |
25 throws ServletException, IOException | |
26 { | |
27 PrintWriter out = response.getWriter(); | |
28 User user = Jtp.getUser(request,response); | |
29 if( user==null ) { | |
30 Jtp.login("You must login to edit your profile.",request,response); | |
31 return; | |
32 } | |
33 String password1 = null; | |
34 String password2 = null; | |
35 String name; | |
36 String errorMsg = null; | |
37 | |
38 if ("save".equals(request.getParameter("action")) && "POST".equals(request.getMethod())) { | |
39 password1 = request.getParameter("password1"); | |
40 password2 = request.getParameter("password2"); | |
41 name = request.getParameter("name"); | |
42 if (!password1.equals(password2) ) { | |
43 errorMsg = "The password fields don't match."; | |
44 } else if (password1.length() > 0 && password1.trim().length() == 0) { | |
45 errorMsg = "Your password must contain valid alphanumeric characters."; | |
46 } else { | |
47 DbDatabase db = user.getSite().getDb(); | |
48 db.beginTransaction(); | |
49 try { | |
50 User u = user.getGoodCopy(); | |
51 if (password1.length() > 0) | |
52 u.setPassword(password1); | |
53 u.setName(name); | |
54 u.update(); | |
55 db.commitTransaction(); | |
56 String pwd = u.getPasscookie(); | |
57 ServletUtils.setCookie(request,response,"username", HtmlUtils.urlEncode(name), false, null); | |
58 ServletUtils.setCookie(request,response,"password", HtmlUtils.urlEncode(pwd), false, null); | |
59 | |
60 StringBuffer js = new StringBuffer(); | |
61 js.append("if (parent.nabbleinfo) {"); | |
62 js.append("Nabble.setCookie('username','").append(HtmlUtils.javascriptStringEncode(HtmlUtils.urlEncode(name))).append("');"); | |
63 js.append("Nabble.setCookie('password','").append(HtmlUtils.javascriptStringEncode(HtmlUtils.urlEncode(pwd))).append("');"); | |
64 js.append("}"); | |
65 | |
66 Shared.javascriptRedirect(request,response, "/template/NamlServlet.jtp?macro=user_profile", js.toString()); | |
67 return; | |
68 } catch(ModelException e) { | |
69 errorMsg = e.getMessage(); | |
70 } finally { | |
71 db.endTransaction(); | |
72 } | |
73 } | |
74 } else { | |
75 name = user.getName(); | |
76 } | |
77 %> | |
78 <html> | |
79 <head> | |
80 <% Shared.title(request,response,"Edit Personal Information"); %> | |
81 </head> | |
82 <body> | |
83 <% Shared.minHeaderGlobal(request, response); %> | |
84 <% Shared.profileHeading(request,out,user,"Edit Personal Information"); %> | |
85 <% Shared.errorMessage(request,response,errorMsg, "Please re-enter the information and click on \"Update Information\"."); %> | |
86 <style> | |
87 div.field-title { | |
88 margin-top: 0; | |
89 } | |
90 </style> | |
91 <form method=post action="EditProfile.jtp"> | |
92 <input type=hidden name="action" value="save"> | |
93 | |
94 <div class="field-box light-border-color"> | |
95 <div class="second-font field-title">Email</div> | |
96 <div class="weak-color"> | |
97 <%=user.getEmail()%> | |
98 » <a href="ChangeEmail.jtp">Change Email</a> | |
99 </div> | |
100 </div> | |
101 | |
102 <div class="field-box light-border-color" id="username-field" > | |
103 <div class="second-font field-title">Your User Name</div> | |
104 <div class="weak-color"> | |
105 Your user name must be unique in <%=user.getSite().getRootNode().getSubjectHtml()%>. | |
106 </div> | |
107 <div><input name="name" size="25" maxlength="25" value="<%=HtmlUtils.htmlEncode(Jtp.hideNull(name))%>" /></div> | |
108 </div> | |
109 | |
110 <div class="field-box light-border-color"> | |
111 <div class="second-font field-title">Change Password</div> | |
112 <div class="weak-color">Nabble encrypts your password (<a href="<%=Help.password.url(request)%>">?</a>)</div> | |
113 <table style="margin: .4em 0" class="shaded-bg-color"> | |
114 <tr valign="top"> | |
115 <td class="form-label" style="padding-top:.6em">Password: </td> | |
116 <td><input type="password" name="password1" size="25" value="<%=Jtp.hideNull(password1)%>"/></td> | |
117 </tr> | |
118 <tr> | |
119 <td class="form-label">Confirm Password: </td> | |
120 <td><input type="password" name="password2" size="25" value="<%=Jtp.hideNull(password2)%>"/></td> | |
121 </tr> | |
122 </table> | |
123 </div> | |
124 | |
125 <div class="field-box light-border-color" style="padding-top:0"> | |
126 <input type=submit value="Update Personal Information" /> | |
127 or <a href="/template/NamlServlet.jtp?macro=user_profile">Cancel</a> | |
128 </div> | |
129 </form> | |
130 | |
131 <% Shared.footer(request,response); %> | |
132 <% Shared.analytics(request,response); %> | |
133 </body> | |
134 </html> | |
135 <% | |
136 } | |
137 } | |
138 %> |