aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src')
-rw-r--r--juick-www/src/main/java/com/juick/www/Main.java14
-rw-r--r--juick-www/src/main/java/com/juick/www/RSS.java63
-rw-r--r--juick-www/src/main/java/com/juick/www/SignUp.java86
-rw-r--r--juick-www/src/main/resources/layouts/rss.xml38
-rw-r--r--juick-www/src/main/resources/views/signup.html41
5 files changed, 131 insertions, 111 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Main.java b/juick-www/src/main/java/com/juick/www/Main.java
index 57704f36..af8711ed 100644
--- a/juick-www/src/main/java/com/juick/www/Main.java
+++ b/juick-www/src/main/java/com/juick/www/Main.java
@@ -210,7 +210,12 @@ public class Main extends HttpServlet implements Stream.StreamListener {
String uname = uri.substring(5);
int uid = UserQueries.getUIDbyName(sql, uname);
if (uid > 0) {
- rss.doGet(sql, request, response, uid, uname);
+ try {
+ rss.doGet(sql, response, uid);
+ } catch (PebbleException e) {
+ log("pebble exception", e);
+ response.sendError(500);
+ }
} else {
response.sendError(404);
}
@@ -230,7 +235,12 @@ public class Main extends HttpServlet implements Stream.StreamListener {
} else if (uri.startsWith("/_twitter")) {
twitterAuth.doGet(sql, request, response);
} else if (uri.equals("/signup")) {
- signup.doGet(sql, request, response);
+ try {
+ signup.doGet(sql, request, response);
+ } catch (PebbleException e) {
+ log("pebble exception", e);
+ response.sendError(500);
+ }
} else if (uri.equals("/help") || uri.equals("/help/")) {
help.doRedirectToHelpIndex(response);
} else if (uri.startsWith("/help/")) {
diff --git a/juick-www/src/main/java/com/juick/www/RSS.java b/juick-www/src/main/java/com/juick/www/RSS.java
index 23120140..f27ea539 100644
--- a/juick-www/src/main/java/com/juick/www/RSS.java
+++ b/juick-www/src/main/java/com/juick/www/RSS.java
@@ -19,16 +19,18 @@ package com.juick.www;
import com.juick.Message;
import com.juick.server.MessagesQueries;
+import com.mitchellbosecke.pebble.error.PebbleException;
+import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
*
@@ -38,7 +40,7 @@ public class RSS {
private static final SimpleDateFormat sdfRSS = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
- protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, int uid, String uname) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletResponse response, int uid) throws ServletException, IOException, PebbleException {
List<Integer> mids = MessagesQueries.getUserBlog(sql, uid, 0, 0);
if (mids.isEmpty()) {
response.sendError(404);
@@ -47,55 +49,16 @@ public class RSS {
List<Message> msgs = MessagesQueries.getMessages(sql, mids);
+ msgs.forEach(m -> Utils.formatMessage(m.getText()));
+
response.setContentType("application/rss+xml; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
- out.println("<?xml version='1.0' encoding='utf-8'?>");
- out.println("<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:slash='http://purl.org/rss/1.0/modules/slash/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:media='http://search.yahoo.com/mrss/' xmlns:juick='http://juick.com/'>");
- out.println("<channel>");
- out.println("<atom:link href='http://rss.juick.com/" + uname + "/blog' rel='self' type='application/rss+xml'/>");
- out.println("<title>" + uname + " - Juick</title>");
- out.println("<link>http://juick.com/" + uname + "/</link>");
- out.println("<description>The latest messages by @" + uname + " at Juick</description>");
- out.println("<image><url>http://i.juick.com/a/" + uid + ".png</url><title>" + uname + " - Juick</title><link>http://juick.com/" + uname + "/</link></image>");
-
- for (Message msg : msgs) {
- out.println("<item>");
- out.println("<link>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</link>");
- out.println("<guid>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</guid>");
-
- out.print("<title><![CDATA[@" + msg.getUser().getUName() + ":");
- if (!msg.Tags.isEmpty()) {
- for (int n = 0; n < msg.Tags.size(); n++) {
- out.print(" *" + msg.Tags.get(n));
- }
- }
- out.println("]]></title>");
- out.println("<description><![CDATA[" + Utils.formatMessage(msg.getText()) + "]]></description>");
-
- Date date = msg.getDate();
- out.println("<pubDate>" + sdfRSS.format(date) + "</pubDate>");
-
-
- out.println("<comments>http://juick.com/" + msg.getUser().getUName() + "/" + msg.getMID() + "</comments>");
- if (!msg.Tags.isEmpty()) {
- for (int n = 0; n < msg.Tags.size(); n++) {
- out.println("<category>" + msg.Tags.get(n) + "</category>");
- }
- }
- if (msg.AttachmentType != null) {
- if (msg.AttachmentType.equals("jpg")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".jpg' type='image/jpeg'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".jpg'/>");
- } else if (msg.AttachmentType.equals("png")) {
- out.println("<media:content url='http://i.juick.com/photos-1024/" + msg.getMID() + ".png' type='image/png'/>");
- out.println("<media:thumbnail url='http://i.juick.com/ps/" + msg.getMID() + ".png'/>");
- }
- }
- out.println("<juick:user uid='" + msg.getUser().getUID() + "'/>");
- out.println("</item>");
- }
-
- out.println("</channel></rss>");
+ PebbleTemplate template = Utils.getEngine().getTemplate("layouts/rss.xml");
+ Map<String, Object> context = new HashMap<>();
+ context.put("user", msgs.stream().findFirst().get().getUser());
+ context.put("msgs", msgs);
+ context.put("sdfRSS", sdfRSS);
+ template.evaluate(out, context);
}
}
}
diff --git a/juick-www/src/main/java/com/juick/www/SignUp.java b/juick-www/src/main/java/com/juick/www/SignUp.java
index a67d049a..43c82a9a 100644
--- a/juick-www/src/main/java/com/juick/www/SignUp.java
+++ b/juick-www/src/main/java/com/juick/www/SignUp.java
@@ -18,6 +18,8 @@
package com.juick.www;
import com.juick.server.UserQueries;
+import com.mitchellbosecke.pebble.error.PebbleException;
+import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -28,7 +30,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
*
@@ -36,7 +40,7 @@ import java.util.List;
*/
public class SignUp {
- protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, PebbleException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
String type = request.getParameter("type");
@@ -47,14 +51,19 @@ public class SignUp {
}
String account = null;
- if (type.equals("fb")) {
- account = getFacebookNameByHash(sql, hash);
- } else if (type.equals("vk")) {
- account = getVKNameByHash(sql, hash);
- } else if (type.equals("xmpp")) {
- account = getJIDByHash(sql, hash);
- } else if (type.equals("durov")) {
- account = getTelegramNameByHash(sql, hash);
+ switch (type) {
+ case "fb":
+ account = getFacebookNameByHash(sql, hash);
+ break;
+ case "vk":
+ account = getVKNameByHash(sql, hash);
+ break;
+ case "xmpp":
+ account = getJIDByHash(sql, hash);
+ break;
+ case "durov":
+ account = getTelegramNameByHash(sql, hash);
+ break;
}
if (account == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
@@ -63,53 +72,14 @@ public class SignUp {
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
- PageTemplates.pageHead(out, visitor, "Новый пользователь", null);
- PageTemplates.pageNavigation(out, visitor, null);
-
- out.println("<section id=\"content\">");
-
- out.print("<h1 class=\"signup-h1\">");
- if (type.charAt(0) == 'f') {
- out.print("<img src=\"//static.juick.com/settings/facebook.png\" alt=\"Facebook\"/>");
- } else if (type.charAt(0) == 'v') {
- out.print("<img src=\"//static.juick.com/settings/vk.png\" alt=\"VKontakte\"/>");
- } else if (type.charAt(0) == 'x') {
- out.print("<img src=\"//static.juick.com/settings/xmpp.png\" alt=\"XMPP\"/>");
- } else if (type.charAt(0) == 'd') {
- out.print("<img src=\"//telegram.org/favicon.ico?3\" alt=\"Telegram\"/>");
- }
- out.println(account + "</h1>");
-
- out.println("<h2 class=\"signup-h2\">Связать с существующим аккаунтом Juick</h2>");
- out.println("<form action=\"/signup\" method=\"post\">");
- out.println("<input type=\"hidden\" name=\"action\" value=\"link\"/>");
- out.println("<input type=\"hidden\" name=\"type\" value=\"" + type + "\"/>");
- out.println("<input type=\"hidden\" name=\"hash\" value=\"" + hash + "\"/>");
- if (visitor.getUID() > 0) {
- out.println("<input type=\"submit\" value=\"Связать с этим аккаунтом\"/>");
- } else {
- out.println("<p>Имя пользователя: <input type=\"text\" name=\"username\"/></p>");
- out.println("<p>Пароль: <input type=\"password\" name=\"password\"/></p>");
- out.println("<p><input type=\"submit\" value=\" OK \"/></p>");
- }
- out.println("</form>");
-
- out.println("<hr class=\"signup-hr\"/>");
-
- out.println("<h2 class=\"signup-h2\">Создать новый аккаунт Juick</h2>");
- out.println("<form action=\"/signup\" method=\"post\">");
- out.println("<input type=\"hidden\" name=\"action\" value=\"new\"/>");
- out.println("<input type=\"hidden\" name=\"type\" value=\"" + type + "\"/>");
- out.println("<input type=\"hidden\" name=\"hash\" value=\"" + hash + "\"/>");
- out.println("<p>Имя пользователя: <input type=\"text\" name=\"username\" id=\"username\"/><br/><i>(От 2-х до 16-и латинских символов и/или цифр, дефис)</i></p>");
- out.println("<p>Пароль: <input type=\"password\" name=\"password\"/><br/><i>(от 6-и до 32-х символов)</i></p>");
- out.println("<p><input type=\"submit\" value=\" OK \"/></p>");
- out.println("</form>");
-
- out.println("</section>");
-
- PageTemplates.pageFooter(request, out, visitor, false);
- PageTemplates.pageEnd(out);
+ PebbleTemplate template = Utils.getEngine().getTemplate("views/signup.html");
+ Map<String, Object> context = new HashMap<>();
+ context.put("title", "Новый пользователь");
+ context.put("visitor", visitor);
+ context.put("account", account);
+ context.put("type", type);
+ context.put("hash", hash);
+ template.evaluate(out, context);
}
}
@@ -233,9 +203,7 @@ public class SignUp {
private String getVKNameByHash(JdbcTemplate sql, String hash) {
List<Pair<String, String>> logins = sql.query("SELECT vk_name,vk_link FROM vk WHERE loginhash=?",
- (rs, num) -> {
- return Pair.of(rs.getString(1), rs.getString(2));
- }, hash);
+ (rs, num) -> Pair.of(rs.getString(1), rs.getString(2)), hash);
if (logins.size() > 0) {
return "<a href=\"http://vk.com/" + logins.get(0).getRight() + "\" rel=\"nofollow\">" + logins.get(0).getLeft() + "</a>";
}
diff --git a/juick-www/src/main/resources/layouts/rss.xml b/juick-www/src/main/resources/layouts/rss.xml
new file mode 100644
index 00000000..61dd3be8
--- /dev/null
+++ b/juick-www/src/main/resources/layouts/rss.xml
@@ -0,0 +1,38 @@
+<?xml version='1.0' encoding='utf-8'?>
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/'
+ xmlns:juick='http://juick.com/'>
+ <channel>
+ <atom:link href='http://rss.juick.com/{{ user.getUName() }}/blog' rel='self' type='application/rss+xml'/>
+ <title>{{ user.getUName() }} - Juick</title>
+ <link>http://juick.com/{{ user.getUName() }}/</link>
+ <description>The latest messages by @{{ user.getUName() }} at Juick</description>
+ <image>
+ <url>http://i.juick.com/a/{{ user.getUID() }}.png</url>
+ <title>{{ user.getUName() }} - Juick</title>
+ <link>http://juick.com/{{ user.getUName() }}/</link>
+ </image>
+ {% for msg in msgs %}
+ <item>
+ <link>http://juick.com/{{ msg.getUser().getUName() }}/{{ msg.getMID() }}</link>
+ <guid>http://juick.com/{{ msg.getUser().getUName() }}/{{ msg.getMID() }}</guid>
+ <title><![CDATA[@{{ msg.getUser().getUName() }}: {% for tag in msg.Tags %} *{{ tag }}{% endfor %}]]></title>
+ <description><![CDATA[{{ msg.getText() | raw }}]]></description>
+ <pubDate>{{ sdfRSS.format(msg.getDate()) }}</pubDate>
+ <comments>http://juick.com/{{ msg.getUser().getUName() }}/{{ msg.getMID() }}</comments>
+ {% for tag in msg.Tags %}
+ <category>{{ tag }}</category>
+ {% endfor %}
+ {% if msg.AttachmentType is not empty %}
+ {% if msg.AttachmentType == "jpg" %}
+ <media:content url='http://i.juick.com/photos-1024/{{ msg.getMID() }}.jpg' type='image/jpeg'/>
+ <media:thumbnail url='http://i.juick.com/ps/{{ msg.getMID() }}.jpg'/>
+ {% elseif msg.AttachmentType == "png" %}
+ <media:content url='http://i.juick.com/photos-1024/{{ msg.getMID() }}.png' type='image/png'/>
+ <media:thumbnail url='http://i.juick.com/ps/{{ msg.getMID() }}.png'/>
+ {% endif %}
+ {% endif %}
+ <juick:user uid='{{ msg.getUser().getUID() }}'/>
+ </item>
+ {% endfor %}
+ </channel>
+</rss> \ No newline at end of file
diff --git a/juick-www/src/main/resources/views/signup.html b/juick-www/src/main/resources/views/signup.html
new file mode 100644
index 00000000..724ad961
--- /dev/null
+++ b/juick-www/src/main/resources/views/signup.html
@@ -0,0 +1,41 @@
+{% extends "layouts/content.html" %}
+{% block content %}
+<h1 class="signup-h1">
+ {% if type | slice(0, 1) == 'f' %}
+ <img src="//static.juick.com/settings/facebook.png" alt="Facebook"/>
+ {% elseif type | slice(0, 1) == 'v' %}
+ <img src="//static.juick.com/settings/vk.png" alt="VKontakte"/>
+ {% elseif type | slice(0, 1) == 'x' %}
+ <img src="//static.juick.com/settings/xmpp.png" alt="XMPP"/>
+ {% elseif type | slice(0, 1) == 'd' %}
+ <img src="//telegram.org/favicon.ico?3" alt="Telegram"/>
+ {% endif %}
+ {{ account | raw }}</h1>
+
+<h2 class="signup-h2">Связать с существующим аккаунтом Juick</h2>
+<form action="/signup" method="post">
+ <input type="hidden" name="action" value="link"/>
+ <input type="hidden" name="type" value="{{ type }}"/>
+ <input type="hidden" name="hash" value="{{ hash }}"/>
+ {% if visitor.getUID() > 0 %}
+ <input type="submit" value="Связать с этим аккаунтом"/>
+ {% else %}
+ <p>Имя пользователя: <input type="text" name="username"/></p>
+ <p>Пароль: <input type="password" name="password"/></p>
+ <p><input type="submit" value=" OK "/></p>
+ {% endif %}
+</form>
+
+<hr class="signup-hr"/>
+
+<h2 class="signup-h2">Создать новый аккаунт Juick</h2>
+<form action="/signup" method="post">
+ <input type="hidden" name="action" value="new"/>
+ <input type="hidden" name="type" value="{{ type }}"/>
+ <input type="hidden" name="hash" value="{{ hash }}"/>
+ <p>Имя пользователя: <input type="text" name="username" id="username"/><br/><i>(От 2-х до 16-и латинских символов
+ и/или цифр, дефис)</i></p>
+ <p>Пароль: <input type="password" name="password"/><br/><i>(от 6-и до 32-х символов)</i></p>
+ <p><input type="submit" value=" OK "/></p>
+</form>
+{% endblock %} \ No newline at end of file