0
|
1 <%
|
|
2 package global.web;
|
|
3
|
|
4 import java.io.IOException;
|
|
5 import java.io.PrintWriter;
|
|
6 import java.io.StringWriter;
|
|
7 import javax.servlet.http.HttpServlet;
|
|
8 import javax.servlet.http.HttpServletRequest;
|
|
9 import javax.servlet.http.HttpServletResponse;
|
|
10 import org.apache.lucene.index.Term;
|
|
11 import org.apache.lucene.search.IndexSearcher;
|
|
12 import org.apache.lucene.search.TopDocs;
|
|
13 import org.apache.lucene.search.Query;
|
|
14 import org.apache.lucene.search.ScoreDoc;
|
|
15 import org.apache.lucene.search.TermQuery;
|
|
16 import fschmidt.util.mail.Mail;
|
|
17 import fschmidt.util.mail.MailAddress;
|
|
18 import fschmidt.util.mail.MailHome;
|
|
19 import fschmidt.util.mail.PlainTextContent;
|
|
20 import global.Site;
|
|
21 import global.HtmlGlobalUtils;
|
|
22
|
|
23
|
|
24 public final class UserSites extends HttpServlet {
|
|
25
|
|
26 protected void service(HttpServletRequest request,HttpServletResponse response)
|
|
27 throws IOException
|
|
28 {
|
|
29 PrintWriter out = response.getWriter();
|
|
30 boolean isValid = true;
|
|
31 boolean isSent = false;
|
|
32 String email = request.getParameter("email");
|
|
33 if( email == null ) {
|
|
34 email = "";
|
|
35 } else {
|
|
36 email = email.trim();
|
|
37 MailAddress to = new MailAddress(email);
|
|
38 isValid = to.isValid();
|
|
39 if( isValid ) {
|
|
40 Mail mail = MailHome.newMail();
|
|
41 mail.setTo(to);
|
|
42 mail.setFrom( new MailAddress("no-reply@nabble.com","Nabble") );
|
|
43 mail.setSubject("Your Nabble Apps");
|
|
44 mail.setContent(new PlainTextContent(text(email)));
|
|
45 MailHome.getDefaultSmtpServer().send(mail);
|
|
46 isSent = true;
|
|
47 }
|
|
48 }
|
|
49 %>
|
|
50 <!DOCTYPE html>
|
|
51 <html lang="en">
|
|
52 <head>
|
|
53 <% HtmlGlobalUtils.head(request, response, "Your Apps"); %>
|
|
54 </head>
|
|
55 <body lato>
|
|
56 <% HtmlGlobalUtils.header(request,response); %>
|
|
57 <div content center paddingTop>
|
|
58 <h1 oswald>Your Nabble Apps</h1>
|
|
59 <p>
|
|
60 Nabble can send you a list with all apps that you currently own.
|
|
61 </p>
|
|
62 <%
|
|
63 if (!isSent) {
|
|
64 %>
|
|
65 <form action="UserSites.jtp">
|
|
66 <p>
|
|
67 <input name="email" type="text" value="<%=email%>" size="30" placeholder="Email address"/>
|
|
68 <input type="submit" value="Submit"/>
|
|
69 </p>
|
|
70 </form>
|
|
71 <%
|
|
72 if( !isValid ) {
|
|
73 %><p>invalid email address</p><%
|
|
74 }
|
|
75 } else {
|
|
76 %><div class="info-message" style="padding:.5em">An email has been sent to you.</div><%
|
|
77 }
|
|
78 %>
|
|
79 </div>
|
|
80 <% HtmlGlobalUtils.footer(request,response); %>
|
|
81 </body>
|
|
82 </html>
|
|
83 <%
|
|
84 }
|
|
85
|
|
86 private static String text(String email) {
|
|
87 try {
|
|
88 IndexSearcher searcher = new IndexSearcher(Site.dir());
|
|
89 Query q = new TermQuery(new Term(Site.OWNER_EMAIL_FLD,email));
|
|
90 TopDocs hits = searcher.search( q, 500 );
|
|
91 try {
|
|
92 StringWriter buf = new StringWriter();
|
|
93 PrintWriter out = new PrintWriter(buf);
|
|
94 %>
|
|
95 Dear Nabble user,
|
|
96 <% if( hits.totalHits == 0 ){ %>
|
|
97 You don't have any sites on Nabble.
|
|
98 <% } else { %>
|
|
99 Here are your Nabble apps:
|
|
100 <% for( ScoreDoc sd : hits.scoreDocs ) {
|
|
101 Site site = new Site( searcher.doc(sd.doc) );
|
|
102 %>
|
|
103 <%=site.url()%>
|
|
104 <%
|
|
105 }
|
|
106 }
|
|
107 %>
|
|
108 Regards,
|
|
109 The Nabble team
|
|
110 <%
|
|
111 out.flush();
|
|
112 return buf.toString();
|
|
113 } finally {
|
|
114 searcher.close();
|
|
115 }
|
|
116 } catch(IOException e) {
|
|
117 throw new RuntimeException(e);
|
|
118 }
|
|
119 }
|
|
120
|
|
121 }
|
|
122 %>
|