diff options
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/SignUp.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/SignUp.java | 86 |
1 files changed, 27 insertions, 59 deletions
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>"; } |