0
|
1 <%
|
|
2 package nabble.view.web.more;
|
|
3
|
|
4 import fschmidt.db.DbDatabase;
|
|
5 import fschmidt.util.mail.MailAddress;
|
|
6 import fschmidt.util.servlet.CanonicalUrl;
|
|
7 import nabble.model.Db;
|
|
8 import nabble.model.Message;
|
|
9 import nabble.model.ModelException;
|
|
10 import nabble.model.ModelHome;
|
|
11 import nabble.model.Site;
|
|
12 import nabble.model.User;
|
|
13 import nabble.naml.compiler.Template;
|
|
14 import nabble.naml.compiler.TemplatePrintWriter;
|
|
15 import nabble.naml.namespaces.BasicNamespace;
|
|
16 import nabble.view.lib.Jtp;
|
|
17 import nabble.view.lib.NewSiteMail;
|
|
18 import nabble.view.lib.Permissions;
|
|
19 import nabble.view.lib.Shared;
|
|
20 import nabble.view.lib.UrlMappable;
|
|
21 import nabble.view.lib.Recaptcha;
|
|
22 import nabble.view.web.app.Languages;
|
|
23 import nabble.view.web.template.NabbleNamespace;
|
|
24
|
|
25 import javax.servlet.ServletException;
|
|
26 import javax.servlet.http.HttpServlet;
|
|
27 import javax.servlet.http.HttpServletRequest;
|
|
28 import javax.servlet.http.HttpServletResponse;
|
|
29 import java.io.IOException;
|
|
30 import java.io.PrintWriter;
|
|
31 import java.io.StringWriter;
|
|
32 import java.util.Collections;
|
|
33 import java.util.HashMap;
|
|
34 import java.util.Map;
|
|
35 import java.util.regex.Matcher;
|
|
36 import java.util.regex.Pattern;
|
28
|
37 import org.slf4j.Logger;
|
|
38 import org.slf4j.LoggerFactory;
|
0
|
39
|
|
40
|
|
41 public final class ForumStart extends HttpServlet implements UrlMappable, CanonicalUrl {
|
28
|
42 private static final Logger logger = LoggerFactory.getLogger(ForumStart.class);
|
0
|
43
|
|
44 private static final Pattern URL_PATTERN = Pattern.compile("/free-(forum|gallery|newspaper|blog|mailing-list)\\.html$");
|
|
45
|
|
46 public static String url(String what) {
|
|
47 return Jtp.defaultContextUrl() + path(what);
|
|
48 }
|
|
49
|
|
50 public static String path(String what) {
|
|
51 return "/free-" + what + ".html";
|
|
52 }
|
|
53
|
|
54 public String getCanonicalUrl(HttpServletRequest request) {
|
|
55 return url( request.getParameter("what") );
|
|
56 }
|
|
57
|
|
58 public Map<String,String[]> getParameterMapFromUrl(HttpServletRequest request,String mappedUrl) {
|
|
59 Matcher m = URL_PATTERN.matcher(mappedUrl);
|
|
60 if( !m.find() )
|
|
61 throw new RuntimeException();
|
|
62 Map<String,String[]> params = new HashMap<String,String[]>();
|
|
63 String what = m.group(1);
|
|
64 params.put("what",new String[]{what});
|
|
65 return params;
|
|
66 }
|
|
67
|
|
68 public Pattern getUrlPattern() {
|
|
69 return URL_PATTERN;
|
|
70 }
|
|
71
|
|
72 protected void service(HttpServletRequest request,HttpServletResponse response)
|
|
73 throws ServletException, IOException
|
|
74 {
|
|
75 build(request, response, Collections.<String,String>emptyMap(), Collections.<String,String>emptyMap());
|
|
76 }
|
|
77
|
|
78 private static void build(HttpServletRequest request,HttpServletResponse response, Map<String,String> values, Map<String,String> errors)
|
|
79 throws ServletException, IOException
|
|
80 {
|
|
81 PrintWriter out = response.getWriter();
|
|
82 String what = request.getParameter("what");
|
|
83 if (what == null)
|
|
84 what = "Forum";
|
|
85 else if ("mailing-list".equals(what))
|
|
86 what = "Mailing List";
|
|
87 else
|
|
88 what = Jtp.capitalize(what);
|
|
89
|
|
90 String imgName = what.toLowerCase();
|
|
91 if ("Mailing List".equals(what))
|
|
92 imgName = "mailing-list";
|
|
93
|
|
94 %>
|
|
95 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
96 <html>
|
|
97 <head>
|
|
98 <% Shared.head(request,response); %>
|
|
99 <title>Nabble - Free <%=what%> Setup</title>
|
|
100 <meta name="robots" content="noindex"/>
|
|
101 <META NAME="description" CONTENT="Setting up a free <%=what.toLowerCase()%> on Nabble is quick and easy. Fill in one simple form and you are done.">
|
|
102 <META NAME="keywords" CONTENT="free <%=what.toLowerCase()%>, hosted <%=what.toLowerCase()%>, simple, embeddable <%=what.toLowerCase()%>, customizable">
|
|
103 <% /*Shared.canonical(request, response);*/ %>
|
|
104 <style type="text/css">
|
|
105 div.center-content {
|
|
106 margin:0px auto;
|
|
107 margin-bottom: 3em;
|
|
108 }
|
|
109 td.column1 {
|
|
110 text-align:right;
|
|
111 width:7em;
|
|
112 white-space:nowrap;
|
|
113 }
|
|
114 input[type=text],input[type=password] {
|
|
115 padding:.4em 0;
|
|
116 }
|
|
117 div.field-title {
|
|
118 margin-top:.3em;
|
|
119 }
|
|
120 .important { font-weight:bold }
|
|
121 label { vertical-align:-15%; }
|
|
122 </style>
|
|
123 <script type="text/javascript">
|
|
124 $(document).ready(function() {
|
|
125 $('#username').focus();
|
|
126 });
|
|
127
|
|
128 function singleFormSubmit(f) {
|
|
129 if (f.done)
|
|
130 return false;
|
|
131 f.done = true;
|
|
132 $('#submit-btn').hide();
|
|
133 var $div = $('#wait-message');
|
|
134 function loading1() { $div.fadeTo(300,0.3,loading2); };
|
|
135 function loading2() { $div.fadeTo(300,1,loading1); };
|
|
136 loading1();
|
|
137 return true;
|
|
138 };
|
|
139 </script>
|
|
140 <%= Recaptcha.JS %>
|
|
141 </head>
|
|
142 <body style="text-align:center">
|
|
143 <% Shared.minHeaderGlobal(request,response); %>
|
|
144
|
|
145 <div class="center-content">
|
|
146 <img src="/images/logo_nabble_home.png" border="0" alt="Nabble - free forums for everyone"/><br />
|
|
147 <h1 style="color:#979797">Start Your <%=what%></h1>
|
|
148
|
|
149 <% if (errors.size() > 0) { %>
|
|
150 <div class="error-message important" style="margin:1em;padding:.5em 0">
|
|
151 <% String generic = errors.get("generic"); %>
|
|
152 <%=generic != null? generic : errors.size() > 0? "Please check the errors below" : ""%>
|
|
153 </div>
|
|
154 <% } %>
|
|
155
|
|
156 <form action="/more/ForumStart$Save.jtp" method="post" accept-charset="UTF-8" onsubmit="return singleFormSubmit(this)">
|
|
157 <input type="hidden" name="type" value="<%=what.toLowerCase().replace(" ","")%>" />
|
|
158 <input type="hidden" name="what" value="<%=what%>" />
|
|
159
|
|
160 <div style="text-align:left;width:50em;margin:0 auto">
|
|
161 <div style="border-bottom:2px solid #eeeeee;padding:1em">
|
|
162 <div class="weak-color" style="width:12em;text-align:center;float:left">
|
|
163 <div style="font-weight:bold">Account</div>
|
|
164 <img src="/images/account.png" width="84" height="45"/>
|
|
165 <div style="margin-top:1em;font-size:80%">
|
|
166 You will receive an email with a link to activate your account
|
|
167 </div>
|
|
168 </div>
|
|
169 <table>
|
|
170 <tr>
|
|
171 <td class="column1"><div class="second-font field-title">User Name</div></td>
|
|
172 <td><input type="text" id="username" size="35" maxlength="30" name="username" value="<%=Jtp.hideNull(values.get("username"))%>" /></td>
|
|
173 <td class="important"><%=errors.containsKey("username")? errors.get("username"):""%></td>
|
|
174 </tr>
|
|
175 <tr>
|
|
176 <td class="column1"><div class="second-font field-title">Email</div></td>
|
|
177 <td><input type="text" size="35" maxlength="60" name="email" value="<%=Jtp.hideNull(values.get("email"))%>"/></td>
|
|
178 <td class="important"><%=errors.containsKey("email")? errors.get("email"):""%></td>
|
|
179 </tr>
|
|
180 <tr>
|
|
181 <td class="column1"><div class="second-font field-title">Password</div></td>
|
|
182 <td><input type="password" size="35" maxlength="15" name="password" value="<%=Jtp.hideNull(values.get("password"))%>"/></td>
|
|
183 <td class="important"><%=errors.containsKey("password")? errors.get("password"):""%></td>
|
|
184 </tr>
|
|
185 <tr>
|
|
186 <td class="column1"><input type="checkbox" id="terms" name="terms" value="y" <%="y".equals(values.get("terms"))?"checked":""%> /></td>
|
|
187 <td colspan=2><label for="terms">I have read and I agree to Nabble's <a href="<%=Jtp.termsUrl(true)%>">Terms of Use</a>.</label></td>
|
|
188 </tr>
|
|
189 </table>
|
|
190 </div>
|
|
191
|
|
192 <div style="padding:1em;overflow:hidden">
|
|
193 <div class="weak-color" style="width:12em;text-align:center;float:left;height:15em">
|
|
194 <div style="font-weight:bold"><%=what%></div>
|
|
195 <img src="/images/homepage/<%=imgName%>.png" alt="Free <%=what.toLowerCase()%>">
|
|
196 </div>
|
|
197 <table>
|
|
198 <tr>
|
|
199 <td class="column1"><div class="second-font field-title">Language</div></td>
|
|
200 <td>
|
|
201 <select name="lang">
|
|
202 <% for( Map.Entry<String,String> entry : Languages.languages.entrySet() ) { %>
|
|
203 <% String lang = request.getParameter("lang"); %>
|
|
204 <% boolean isEnglish = entry.getKey().equals("none"); %>
|
|
205 <% boolean isSelected = (lang == null && isEnglish) || entry.getKey().equals(lang); %>
|
|
206 <option value="<%=entry.getKey()%>" <%=isSelected?"selected=\"true\"":""%>><%=entry.getValue()%></option>
|
|
207 <% } %>
|
|
208 </select>
|
|
209 </td>
|
|
210 <td></td>
|
|
211 </tr>
|
|
212 <tr>
|
|
213 <td colspan="3" style="height:.6em"></td>
|
|
214 </tr>
|
|
215 <tr>
|
|
216 <td class="column1"><div class="second-font field-title"><%=what%> Name</div></td>
|
|
217 <td><input type="text" name="subject" size="30" maxlength="80" value="<%=Jtp.hideNull(values.get("subject"))%>"/></td>
|
|
218 <td class="important"><%=errors.containsKey("subject")? errors.get("subject"):""%></td>
|
|
219 </tr>
|
|
220 <tr>
|
|
221 <td colspan=3 style="padding:.4em 0 0 .6em">
|
|
222 <div class="second-font field-title">Description <span class="weak-color" style="font-weight:normal;">(optional)</span></div>
|
|
223 <textarea rows="7" name="message" wrap="SOFT" style="width:28em"><%=Jtp.hideNull(values.get("message"))%></textarea>
|
|
224 <br><%= Recaptcha.DIV %>
|
|
225 </td>
|
|
226 </tr>
|
|
227 </table>
|
|
228 </div>
|
|
229 <div class="weak-color" style="margin-top:.5em;text-align:center;">
|
|
230 <input id="submit-btn" type="submit" name="save" value="Create <%=what%>" style="padding:.5em .8em;font-size:110%;font-weight:bold"/>
|
|
231 <div id="wait-message" class="important invisible" style="margin:.1em 0">Creating <%=what%>... Please wait</div>
|
|
232 </div>
|
|
233 </div>
|
|
234 </form>
|
|
235 </div>
|
|
236
|
|
237 <% Shared.footer(request,response); %>
|
|
238 <% Shared.analytics(request,response); %>
|
|
239 </body>
|
|
240 </html>
|
|
241 <%
|
|
242 }
|
|
243
|
28
|
244
|
0
|
245 public static class Save extends HttpServlet {
|
|
246
|
|
247 private static String get(String name, HttpServletRequest request) {
|
|
248 String s = request.getParameter(name);
|
28
|
249 return s == null ? null : s.trim();
|
0
|
250 }
|
|
251
|
|
252 protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
253 throws ServletException, IOException
|
|
254 {
|
|
255 String username = get("username", request);
|
|
256 String email = get("email", request);
|
|
257 String password = get("password", request);
|
|
258 boolean agreed = "y".equals(get("terms", request));
|
|
259 String subject = get("subject", request);
|
|
260 String message = get("message", request);
|
|
261
|
|
262 Map<String,String> errors = new HashMap<String,String>();
|
|
263 if (username == null || username.trim().length() == 0)
|
|
264 errors.put("username", "required");
|
|
265 if (email == null || email.length() == 0)
|
|
266 errors.put("email", "required");
|
|
267 else if (!new MailAddress(email).isValid())
|
|
268 errors.put("email", "invalid email");
|
|
269 if (password == null || password.length() < 4)
|
|
270 errors.put("password", "too short");
|
|
271 if (!agreed)
|
|
272 errors.put("generic", "You must agree to the Terms and Conditions");
|
|
273 if (subject == null || subject.length() == 0)
|
|
274 errors.put("subject", "required");
|
|
275
|
|
276 String type = get("type", request);
|
|
277 type = "newspaper".equals(type)? "news" : type;
|
|
278
|
|
279 String extraMessage = "";
|
|
280 if ("mailinglist".equals(type)) {
|
|
281 type = "forum";
|
|
282 StringBuilder m = new StringBuilder();
|
|
283 m.append("\n\nMailing List Options\n");
|
|
284 m.append("Click \"Options > Subscribe via email\" to subscribe to this mailing list;\n");
|
|
285 m.append("Click \"Options > Post by email...\" to get the email address of this mailing list;\n");
|
|
286 m.append("You can post messages via email or through the forum interface below;\n");
|
|
287 m.append("All web posts and emails are archived here.");
|
|
288 extraMessage = m.toString();
|
|
289 }
|
|
290
|
|
291 if (errors.isEmpty()) {
|
|
292 DbDatabase db = Db.dbGlobal();
|
|
293 db.beginTransaction();
|
|
294 try {
|
|
295 Recaptcha.check(request);
|
|
296 Site site = ModelHome.newSite(type,subject, message + extraMessage, Message.Format.TEXT, email, username);
|
|
297 Permissions.addToGroup( (User)site.getRootNode().getOwner(), Permissions.ADMINISTRATORS_GROUP );
|
|
298 String key = site.newRegistration(email,password,username,"/");
|
|
299 db.commitTransaction();
|
|
300
|
|
301 // Track spam activities by IP
|
|
302 ModelHome.setRemoteAddr(site, Jtp.getClientIpAddr(request));
|
|
303
|
|
304 site = site.getGoodCopy();
|
|
305
|
|
306 String lang = request.getParameter("lang");
|
|
307 if (!"none".equals(lang)) {
|
|
308 site.setModuleEnabled(lang, true);
|
|
309 site = site.getGoodCopy();
|
|
310 }
|
|
311
|
|
312 sendRegisterMail(site, email, key);
|
|
313 NewSiteMail.send(site, request, response);
|
|
314 response.sendRedirect(site.getBaseUrl()+"/more/ForumStart$Redirection.jtp");
|
|
315 return;
|
|
316 } catch(ModelException e) {
|
|
317 errors.put("generic", e.getMessage());
|
|
318 } finally {
|
|
319 db.endTransaction();
|
|
320 }
|
|
321 }
|
|
322
|
|
323 Map<String,String> values = new HashMap<String,String>();
|
|
324 values.put("username", username);
|
|
325 values.put("email", email);
|
|
326 values.put("password", password);
|
|
327 values.put("terms", agreed?"y":"");
|
|
328 values.put("subject", subject);
|
|
329 values.put("message", message);
|
|
330 build(request, response, values, errors);
|
|
331 }
|
|
332 }
|
|
333
|
|
334 /** Sets cookies in the site domain */
|
|
335 public static class Redirection extends HttpServlet {
|
|
336
|
|
337 protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
338 throws ServletException, IOException
|
|
339 {
|
|
340 Site site = Jtp.getSite(request);
|
|
341 Shared.javascriptRedirect(request, response, Jtp.url(site.getRootNode()), "Nabble.setVar('appnotice','true');");
|
|
342 }
|
|
343 }
|
|
344
|
|
345 public static void sendRegisterMail(Site site, String email, String key) {
|
|
346 Map<String,Object> args = new HashMap<String,Object>();
|
|
347 args.put("email",email);
|
|
348 args.put("next_url","/");
|
|
349 args.put("key",key);
|
|
350 Template template = site.getTemplate( "send_registration_email",
|
|
351 BasicNamespace.class, NabbleNamespace.class
|
|
352 );
|
|
353 template.run( TemplatePrintWriter.NULL, args,
|
|
354 new BasicNamespace(template), new NabbleNamespace(site)
|
|
355 );
|
|
356 }
|
|
357 }
|
|
358 %>
|