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, "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