" + txt + "
"); - if (msg.getAttachmentType() != null) { - out.println(" "); - } - out.print(" "); - - out.print(" "); - out.print("GET
method.
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- if (request.getCharacterEncoding() == null) {
- request.setCharacterEncoding(CharEncoding.UTF_8);
- }
- String uri = request.getRequestURI();
-
- if (uri.equals("/")) {
- String tag = request.getParameter("tag");
- if (tag != null) {
- Utils.sendPermanentRedirect(response, "/tag/" + URLEncoder.encode(tag, CharEncoding.UTF_8));
- } else {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- home.doGet(sql, sqlSearch, request, response, visitor);
- }
- } else if (uri.equals("/post")) {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0) {
- pagesNewMessage.doGetNewMessage(sql, request, response, visitor);
- } else {
- Utils.sendTemporaryRedirect(response, "/login");
- }
- } else if (uri.equals("/login")) {
- if (request.getQueryString() == null) {
- login.doGetLoginForm(sql, request, response);
- } else {
- login.doGetLogin(sql, request, response);
- }
- } else if (uri.startsWith("/pm/")) {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() == 0) {
- Utils.sendTemporaryRedirect(response, "/login");
- } else {
- switch (uri) {
- case "/pm/inbox":
- try {
- pm.doGetInbox(sql, request, response, visitor);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- break;
- case "/pm/sent":
- try {
- pm.doGetSent(sql, request, response, visitor);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- break;
- default:
- Errors.doGet404(sql, request, response);
- break;
- }
- }
- } else if (uri.startsWith("/rss/")) {
- String uname = uri.substring(5);
- int uid = UserQueries.getUIDbyName(sql, uname);
- if (uid > 0) {
- try {
- rss.doGet(sql, response, uid);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- } else {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- }
- } else if (uri.equals("/logout")) {
- login.doGetLogout(sql, request, response);
- } else if (uri.equals("/settings")) {
- try {
- settings.doGet(sql, request, response);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- } else if (uri.equals("/_fblogin")) {
- loginFacebook.doGet(sql, request, response);
- } else if (uri.equals("/_vklogin")) {
- loginVK.doGet(sql, request, response);
- } else if (uri.startsWith("/_twitter")) {
- twitterAuth.doGet(sql, request, response);
- } else if (uri.equals("/signup")) {
- try {
- signup.doGet(sql, request, response);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- } else if (uri.equals("/help") || uri.equals("/help/")) {
- help.doRedirectToHelpIndex(response);
- } else if (uri.startsWith("/help/")) {
- try {
- help.doGetHelp(sql, request, response);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- } catch (URISyntaxException e) {
- log("help exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- } else if (uri.startsWith("/tag/")) {
- discover.doGet(sql, sqlSearch, request, response);
- } else if (uri.matches("^/\\d+$")) {
- String strID = request.getRequestURI().substring(1);
- int mid = 0;
- try {
- mid = Integer.parseInt(strID);
- } catch (NumberFormatException e) {
- }
- if (mid > 0) {
- com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
- if (author != null) {
- Utils.sendPermanentRedirect(response, "/" + author.getName() + "/" + mid);
- return;
- }
- }
- Errors.doGet404(sql, request, response);
- } else if (uri.matches("^/[^/]+$")) {
- com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, request.getRequestURI().substring(1));
- if (user != null) {
- Utils.sendPermanentRedirect(response, "/" + user.getName() + "/");
- } else {
- Errors.doGet404(sql, request, response);
- }
- } else if (uri.matches("^/.+/.*")) {
- String uriparts[] = uri.split("/");
- com.juick.User user = com.juick.server.UserQueries.getUserByName(sql, uriparts[1]);
- if (user != null && user.getName().equals(uriparts[1]) && !user.isBanned()) {
- if (uriparts.length == 2) { // http://juick.com/username/
- pagesUser.doGetBlog(sql, sqlSearch, request, response, user);
- } else if (uriparts[2].equals("tags")) {
- pagesUser.doGetTags(sql, request, response, user);
- } else if (uriparts[2].equals("friends")) {
- pagesUser.doGetFriends(sql, request, response, user);
- } else if (uriparts[2].equals("readers")) {
- pagesUser.doGetReaders(sql, request, response, user);
- } else {
- int mid = 0;
- try {
- mid = Integer.parseInt(uriparts[2]);
- } catch (NumberFormatException e) {
- }
- if (mid > 0) {
- com.juick.User author = com.juick.server.MessagesQueries.getMessageAuthor(sql, mid);
- if (author != null) {
- if (!author.getName().equals(user.getName())) {
- Utils.sendPermanentRedirect(response, "/" + author.getName() + "/" + mid);
- } else {
- pagesUserThread.doGetThread(sql, request, response, mid);
- }
- } else {
- Errors.doGet404(sql, request, response);
- }
- } else {
- Errors.doGet404(sql, request, response);
- }
- }
- } else if (user != null && !user.isBanned()) {
- Utils.sendPermanentRedirect(response, "/" + user.getName() + "/" + (uriparts.length > 2 ? uriparts[2] : StringUtils.EMPTY));
- } else {
- Errors.doGet404(sql, request, response);
- }
- } else {
- Errors.doGet404(sql, request, response);
- }
- }
-
- /**
- * Handles the HTTP POST
method.
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- if (request.getCharacterEncoding() == null) {
- request.setCharacterEncoding(CharEncoding.UTF_8);
- }
-
- String uri = request.getRequestURI();
- switch (uri) {
- case "/post": {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0 && !visitor.isBanned()) {
- pagesNewMessage.doPostMessage(sql, request, response, xmpp, visitor);
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- break;
- }
- case "/comment": {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0 && !visitor.isBanned()) {
- pagesNewMessage.doPostComment(sql, request, response, xmpp, visitor);
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- break;
- }
- case "/like": {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0 && !visitor.isBanned()) {
- pagesNewMessage.doPostRecomm(sql, request, response, xmpp, visitor);
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- break;
- }
- case "/pm/send": {
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0 && !visitor.isBanned()) {
- pm.doPostPM(sql, request, response, xmpp, visitor);
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- break;
- }
- case "/login":
- login.doPostLogin(sql, request, response);
- break;
- case "/signup":
- signup.doPost(sql, request, response);
- break;
- case "/settings":
- try {
- settings.doPost(sql, request, response);
- } catch (PebbleException e) {
- log("pebble exception", e);
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- break;
- case "/post2":
- com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
- if (visitor.getUid() > 0 && !visitor.isBanned()) {
- xmppPost.doPostMessage(sql, request, response, xmpp, visitor);
- } else {
- response.sendError(HttpServletResponse.SC_FORBIDDEN);
- }
- break;
- default:
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- break;
- }
- }
-}
diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java
deleted file mode 100644
index 43ea039c..00000000
--- a/juick-www/src/main/java/com/juick/www/NewMessage.java
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * Juick
- * Copyright (C) 2008-2011, Ugnich Anton
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see Теги:
"); - printUserTags(sql, out, visitor); - out.println(""); - for (int i = 0; i < tags.size(); i++) { - if (i > 0) { - out.print(" "); - } - String taglink = StringUtils.EMPTY; - try { - taglink = "" + StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()) + ""; - } catch (UnsupportedEncodingException e) { - } - int usagecnt = tags.get(i).getUsageCount(); - if (usagecnt <= max / 5 + min) { - out.print("" + taglink + ""); - } else if (usagecnt <= max / 5 * 2 + min) { - out.print(taglink); - } else if (usagecnt <= max / 5 * 3 + min) { - out.print("" + taglink + ""); - } else if (usagecnt <= max / 5 * 4 + min) { - out.print("" + taglink + ""); - } else { - out.print("" + taglink + ""); - } - } - out.println("
"); - } - - public void doPostMessage(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response, XmppSession xmpp, com.juick.User visitor) throws ServletException, IOException { - String body = request.getParameter("body"); - if (body == null || body.length() < 1 || body.length() > 4096) { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return; - } - body = body.replace("\r", StringUtils.EMPTY); - - ListПоделитесь своим новым постом в социальных сетях:
"); - if (CrosspostQueries.getTwitterTokens(sql, visitor.getUid()).isPresent()) { - out.println(" "); - } - out.println(" "); - out.println(" "); - if (CrosspostQueries.getFacebookToken(sql, visitor.getUid()).isPresent()) { - out.println(" "); - } - out.println(" "); - out.println("Ссылка на сообщение: http://juick.com/" + mid + "
"); - out.println("Чтобы добавлять сообщения и комментарии, представьтесь.
"); - } - out.println("" + txt + "
"); - if (msg.getAttachmentType() != null) { - out.println(" "); - } - out.print(" "); - - out.print(" "); - out.print("Password has been changed.
"; - String hash = com.juick.server.UserQueries.getHashByUID(sql, visitor.getUid()); - Cookie c = new Cookie("hash", hash); - c.setMaxAge(365 * 24 * 60 * 60); - response.addCookie(c); - } - break; - case "main": - NotifyOpts opts = new NotifyOpts(); - opts.setRepliesEnabled(StringUtils.isNotEmpty(request.getParameter("jnotify"))); - opts.setSubscriptionsEnabled(StringUtils.isNotEmpty(request.getParameter("subscr_notify"))); - opts.setRecommendationsEnabled(StringUtils.isNotEmpty(request.getParameter("recomm"))); - if (SubscriptionsQueries.setNotifyOptions(sql, visitor, opts)) { - result = "Notification options has been updated
"; - } - break; - case "about": - UserInfo info = new UserInfo(); - info.setFullName(request.getParameter("fullname")); - info.setCountry(request.getParameter("country")); - info.setUrl(request.getParameter("url")); - info.setDescription(request.getParameter("descr")); - String avatarTmpPath = Utils.receiveMultiPartFile(request.getPart("avatar")); - if (StringUtils.isNotEmpty(avatarTmpPath)) { - String originalExtension = FilenameUtils.getExtension(avatarTmpPath); - String originalName = String.format("%s.%s", visitor.getUid(), originalExtension); - String targetName = String.format("%s.png", visitor.getUid()); - Path ao = Paths.get(imgPath, "ao", originalName); - Path a = Paths.get(imgPath, "a", targetName); - Path as = Paths.get(imgPath, "as", targetName); - Files.move(Paths.get(Utils.getTmpDir(), avatarTmpPath), ao, StandardCopyOption.REPLACE_EXISTING); - Thumbnails.of(ao.toFile()).size(96, 96).toFile(a.toFile()); - Thumbnails.of(ao.toFile()).size(32, 32).toFile(as.toFile()); - } - if (UserQueries.updateUserInfo(sql, visitor, info)) { - result = String.format("Your info is updated.
", visitor.getName()); - } - break; - case "jid-del": - String[] params = request.getParameter("delete").split(";", 2); - int res = -1; - if (params[0].equals("xmpp")) { - res = sql.update("DELETE FROM jids WHERE user_id=? AND jid=?", visitor.getUid(), params[1]); - } else if (params[0].equals("xmpp-unauth")) { - res = sql.update("DELETE FROM auth WHERE user_id=? AND protocol='xmpp' AND account=?", visitor.getUid(), params[1]); - } - if (res == 1) { - result = "Deleted. Back.
"; - } else { - result = "Error
"; - } - break; - case "email": - String newHash = UserQueries.updateSecretEmail(sql, visitor); - if (StringUtils.isNotEmpty(newHash)) { - result = String.format("New secret email: %s@mail.juick.com
" + - "Back.
", newHash); - } else { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return; - } - break; - case "email-add": - try { - sql.queryForObject("SELECT authcode FROM auth WHERE user_id=? AND protocol='email' " + - "AND account=?", String.class, visitor.getUid(), request.getParameter("account")); - } catch (EmptyResultDataAccessException e) { - String authCode = UserUtils.generateHash(8); - if (sql.update("INSERT INTO auth(user_id,protocol,account,authcode) VALUES (?,'email',?,?)", - visitor.getUid(), request.getParameter("account"), authCode) > 0) { - Session session = Session.getDefaultInstance(System.getProperties()); - try { - MimeMessage message = new MimeMessage(session); - message.setFrom(new InternetAddress("noreply@mail.juick.com")); - message.addRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("account"))); - message.setSubject("Juick authorization link"); - message.setText(String.format("Follow link to attach this email to Juick account:\n" + - "http://juick.com/settings?page=auth-email&code=%s\n\n" + - "If you don't know, what this mean - just ignore this mail.\n", authCode)); - Transport.send(message); - result = "Authorization link has been sent to your email. Follow it to proceed.
" + - ""; - - } catch (MessagingException ex) { - logger.error("mail exception", ex); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return; - } - } - } - break; - case "email-del": - if (sql.update("DELETE FROM emails WHERE user_id=? AND email=?", visitor.getUid(), request.getParameter("account")) > 0) { - result = "Deleted. Back.
"; - } else { - result = "An error occured while deleting.
"; - } - break; - case "email-subscr": - sql.update("UPDATE emails SET subscr_hour=NULL WHERE user_id=?", visitor.getUid()); - String email = request.getParameter("account"); - if (StringUtils.isNotEmpty(email)) { - sql.update("UPDATE emails SET subscr_hour=? WHERE user_id=? AND email=?", - request.getParameter("time"), visitor.getUid(), email); - result = String.format("Saved! Will send to %s at %s:00 GMT." + - "
", email, request.getParameter("time")); - } else { - result = "Disabled.
"; - } - break; - case "twitter-del": - sql.update("DELETE FROM twitter WHERE user_id=?", visitor.getUid()); - sql.update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=1741", visitor.getUid()); - for (Cookie cookie : request.getCookies()) { - if (cookie.getName().equals("request_token")) { - cookie.setMaxAge(0); - response.addCookie(cookie); - } - if (cookie.getName().equals("request_token_secret")) { - cookie.setMaxAge(0); - response.addCookie(cookie); - } - } - result = ""; - break; - case "telegram-del": - sql.update("DELETE FROM telegram WHERE user_id=?", visitor.getUid()); - result = ""; - break; - case "facebook-disable": - sql.update("UPDATE facebook SET crosspost=0 WHERE user_id=?", visitor.getUid()); - sql.update("DELETE FROM subscr_users WHERE user_id=? AND suser_id=5863", visitor.getUid()); - result = ""; - break; - case "facebook-enable": - sql.update("UPDATE facebook SET crosspost=1 WHERE user_id=?", visitor.getUid()); - sql.update("INSERT INTO subscr_users(user_id,suser_id,jid,active) VALUES (?,5863,'juick@facebook.juick.com',1)", visitor.getUid()); - result = ""; - break; - case "vk-del": - sql.update("DELETE FROM vk WHERE user_id=?", visitor.getUid()); - result = ""; - break; - default: - response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return; - } - response.setContentType("text/html; charset=UTF-8"); - try (PrintWriter out = response.getWriter()) { - PebbleTemplate template = Utils.getEngine().getTemplate("views/settings_result.html"); - Map← Все записи с тегом " + - StringEscapeUtils.escapeHtml4(paramTag.getName()) + "
"); - } - - PageTemplates.printMessages(out, sql, user, mids, visitor, visitor.getUid() == 0 ? 4 : 5, 0); - - if (mids.size() >= 20) { - String nextpage = "?before=" + mids.get(mids.size() - 1); - if (paramShow != null) { - nextpage += "&show=" + paramShow; - } - if (paramTag != null) { - nextpage += "&tag=" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8); - } - if (paramSearch != null) { - nextpage += "&search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8); - } - out.println(""); - } - - out.println("" + pageUserTags(sql, user, visitor, 0) + "
"); - out.println("" - + friends.get(i).getName() + " | "); - } - - out.println("
" - + readers.get(i).getName() + " | "); - } - - out.println("
Теги:
"); + printUserTags(out, visitor); + out.println(""); + for (int i = 0; i < tags.size(); i++) { + if (i > 0) { + out.print(" "); + } + String taglink = StringUtils.EMPTY; + try { + taglink = "" + StringEscapeUtils.escapeHtml4(tags.get(i).getTag().getName()) + ""; + } catch (UnsupportedEncodingException e) { + } + int usagecnt = tags.get(i).getUsageCount(); + if (usagecnt <= max / 5 + min) { + out.print("" + taglink + ""); + } else if (usagecnt <= max / 5 * 2 + min) { + out.print(taglink); + } else if (usagecnt <= max / 5 * 3 + min) { + out.print("" + taglink + ""); + } else if (usagecnt <= max / 5 * 4 + min) { + out.print("" + taglink + ""); + } else { + out.print("" + taglink + ""); + } + } + out.println("
"); + } + + @RequestMapping(value = "/post", method = RequestMethod.POST) + public void doPostMessage(HttpServletRequest request, HttpServletResponse response, + @RequestParam(required = false) String img, + @RequestParam(required = false) MultipartFile attach) throws IOException { + com.juick.User visitor = webApp.getVisitorUser(request, response); + if (visitor.getUid() == 0) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return; + } + String body = request.getParameter("body"); + if (body == null || body.length() < 1 || body.length() > 4096) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST); + return; + } + body = body.replace("\r", StringUtils.EMPTY); + + ListПоделитесь своим новым постом в социальных сетях:
"); + if (crosspostService.getTwitterTokens(visitor.getUid()).isPresent()) { + out.println(" "); + } + out.println(" "); + out.println(" "); + if (crosspostService.getFacebookToken(visitor.getUid()).isPresent()) { + out.println(" "); + } + out.println(" "); + out.println("Ссылка на сообщение: http://juick.com/" + mid + "
"); + out.println("Чтобы добавлять сообщения и комментарии, представьтесь.
"); + } + out.println("" + txt + "
"); + if (msg.getAttachmentType() != null) { + out.println(" "); + } + out.print(" "); + + out.print(" "); + out.print("Password has been changed.
"; + String hash = userService.getHashByUID(visitor.getUid()); + Cookie c = new Cookie("hash", hash); + c.setMaxAge(365 * 24 * 60 * 60); + response.addCookie(c); + } + break; + case "main": + NotifyOpts opts = new NotifyOpts(); + opts.setRepliesEnabled(StringUtils.isNotEmpty(request.getParameter("jnotify"))); + opts.setSubscriptionsEnabled(StringUtils.isNotEmpty(request.getParameter("subscr_notify"))); + opts.setRecommendationsEnabled(StringUtils.isNotEmpty(request.getParameter("recomm"))); + if (subscriptionService.setNotifyOptions(visitor, opts)) { + result = "Notification options has been updated
"; + } + break; + case "about": + UserInfo info = new UserInfo(); + info.setFullName(request.getParameter("fullname")); + info.setCountry(request.getParameter("country")); + info.setUrl(request.getParameter("url")); + info.setDescription(request.getParameter("descr")); + String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, webApp.getTmpDir()); + if (StringUtils.isNotEmpty(avatarTmpPath)) { + String originalExtension = FilenameUtils.getExtension(avatarTmpPath); + String originalName = String.format("%s.%s", visitor.getUid(), originalExtension); + String targetName = String.format("%s.png", visitor.getUid()); + Path ao = Paths.get(webApp.getImgDir(), "ao", originalName); + Path a = Paths.get(webApp.getImgDir(), "a", targetName); + Path as = Paths.get(webApp.getImgDir(), "as", targetName); + Files.move(Paths.get(webApp.getTmpDir(), avatarTmpPath), ao, StandardCopyOption.REPLACE_EXISTING); + Thumbnails.of(ao.toFile()).size(96, 96).toFile(a.toFile()); + Thumbnails.of(ao.toFile()).size(32, 32).toFile(as.toFile()); + } + if (userService.updateUserInfo(visitor, info)) { + result = String.format("Your info is updated.
", visitor.getName()); + } + break; + case "jid-del": + // FIXME: stop using ugnich-csv in parameters + String[] params = request.getParameter("delete").split(";", 2); + boolean res = false; + if (params[0].equals("xmpp")) { + res = userService.deleteJID(visitor.getUid(), params[1]); + } else if (params[0].equals("xmpp-unauth")) { + res = userService.unauthJID(visitor.getUid(), params[1]); + } + if (res) { + result = "Deleted. Back.
"; + } else { + result = "Error
"; + } + break; + case "email": + String newHash = userService.updateSecretEmail(visitor); + if (StringUtils.isNotEmpty(newHash)) { + result = String.format("New secret email: %s@mail.juick.com
" + + "Back.
", newHash); + } else { + throw new HttpBadRequestException(); + } + break; + case "email-add": + try { + emailService.verifyAddressByCode(visitor.getUid(), request.getParameter("account")); + } catch (EmptyResultDataAccessException e) { + String authCode = UserUtils.generateHash(8); + if (emailService.addVerificationCode(visitor.getUid(), request.getParameter("account"), authCode)) { + Session session = Session.getDefaultInstance(System.getProperties()); + try { + MimeMessage message = new MimeMessage(session); + message.setFrom(new InternetAddress("noreply@mail.juick.com")); + message.addRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("account"))); + message.setSubject("Juick authorization link"); + message.setText(String.format("Follow link to attach this email to Juick account:\n" + + "http://juick.com/settings?page=auth-email&code=%s\n\n" + + "If you don't know, what this mean - just ignore this mail.\n", authCode)); + Transport.send(message); + result = "Authorization link has been sent to your email. Follow it to proceed.
" + + ""; + + } catch (MessagingException ex) { + logger.error("mail exception", ex); + throw new HttpBadRequestException(); + } + } + } + break; + case "email-del": + if (emailService.deleteEmail(visitor.getUid(), request.getParameter("account"))) { + result = "Deleted. Back.
"; + } else { + result = "An error occured while deleting.
"; + } + break; + case "email-subscr": + if (emailService.setSubscriptionHour(visitor.getUid(), request.getParameter("account"), + request.getParameter("time"))) { + result = String.format("Saved! Will send to %s at %s:00 GMT." + + "
", request.getParameter("account"), + request.getParameter("time")); + } else { + result = "Disabled.
"; + } + break; + case "twitter-del": + crosspostService.deleteTwitterToken(visitor.getUid()); + for (Cookie cookie : request.getCookies()) { + if (cookie.getName().equals("request_token")) { + cookie.setMaxAge(0); + response.addCookie(cookie); + } + if (cookie.getName().equals("request_token_secret")) { + cookie.setMaxAge(0); + response.addCookie(cookie); + } + } + result = ""; + break; + case "telegram-del": + telegramService.deleteTelegramUser(visitor.getUid()); + result = ""; + break; + case "facebook-disable": + crosspostService.disableFBCrosspost(visitor.getUid()); + result = ""; + break; + case "facebook-enable": + crosspostService.enableFBCrosspost(visitor.getUid()); + result = ""; + break; + case "vk-del": + crosspostService.deleteVKUser(visitor.getUid()); + result = ""; + break; + default: + throw new HttpBadRequestException(); + } + + model.addAttribute("title", "Настройки"); + model.addAttribute("visitor", visitor); + model.addAttribute("result", result); + return "views/settings_result"; + } +} diff --git a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java new file mode 100644 index 00000000..937a3242 --- /dev/null +++ b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java @@ -0,0 +1,170 @@ +/* + * Juick + * Copyright (C) 2008-2013, Ugnich Anton + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see← Все записи с тегом " + + StringEscapeUtils.escapeHtml4(paramTag.getName()) + "
"); + } + + templates.printMessages(out, user, mids, visitor, visitor.getUid() == 0 ? 4 : 5, 0); + + if (mids.size() >= 20) { + String nextpage = "?before=" + mids.get(mids.size() - 1); + if (paramShow != null) { + nextpage += "&show=" + paramShow; + } + if (paramTag != null) { + nextpage += "&tag=" + URLEncoder.encode(paramTag.getName(), CharEncoding.UTF_8); + } + if (paramSearch != null) { + nextpage += "&search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8); + } + out.println(""); + } + + out.println("" + pageUserTags(user, visitor, 0) + "
"); + out.println("" + + friends.get(i).getName() + " | "); + } + + out.println("
" + + readers.get(i).getName() + " | "); + } + + out.println("