aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-api/src/main/java/com/juick/server/api/Post.java4
-rw-r--r--juick-common/src/main/java/com/juick/server/CommandsManager.java4
-rw-r--r--juick-common/src/main/java/com/juick/service/security/deprecated/RequestParamHashRememberMeServices.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/MessengerManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/ServerManager.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/TelegramBotManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPConnection.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Messages.java14
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Notifications.java8
-rw-r--r--juick-server/src/main/java/com/juick/server/api/PM.java17
-rw-r--r--juick-server/src/main/java/com/juick/server/api/Users.java10
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/Feeds.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java2
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java46
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java8
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Settings.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/SignUp.java4
17 files changed, 63 insertions, 74 deletions
diff --git a/juick-api/src/main/java/com/juick/server/api/Post.java b/juick-api/src/main/java/com/juick/server/api/Post.java
index d007b9af..afe9d2d5 100644
--- a/juick-api/src/main/java/com/juick/server/api/Post.java
+++ b/juick-api/src/main/java/com/juick/server/api/Post.java
@@ -157,7 +157,7 @@ public class Post {
@ResponseStatus(value = HttpStatus.OK)
public Status doPostRecomm(@RequestParam Integer mid) throws Exception {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
com.juick.Message msg = messagesService.getMessage(mid);
@@ -185,7 +185,7 @@ public class Post {
logger.info("got reaction with type: {}", reactionId);
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
com.juick.Message msg = messagesService.getMessage(mid);
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java
index 918e6028..d3be371f 100644
--- a/juick-common/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java
@@ -145,7 +145,7 @@ public class CommandsManager {
User user_to = userService.getUserByName(arguments[0]);
- if (user_to.getUid() > 0) {
+ if (!user_to.isAnonymous()) {
if (!userService.isInBLAny(user_to.getUid(), user_from.getUid())) {
if (pmQueriesService.createPM(user_from.getUid(), user_to.getUid(), body)) {
com.juick.Message jmsg = new com.juick.Message();
@@ -379,7 +379,7 @@ public class CommandsManager {
public CommandResult commandUser(User user, URI attachment, String... arguments) {
User blogUser = userService.getUserByName(arguments[0]);
int page = arguments[1].length();
- if (blogUser.getUid() > 0) {
+ if (!blogUser.isAnonymous()) {
List<Integer> mids = messagesService.getUserBlog(blogUser.getUid(), 0, 0);
return CommandResult.fromString(String.format("Last messages from @%s:\n%s", arguments[0],
printMessages(mids, false)));
diff --git a/juick-common/src/main/java/com/juick/service/security/deprecated/RequestParamHashRememberMeServices.java b/juick-common/src/main/java/com/juick/service/security/deprecated/RequestParamHashRememberMeServices.java
index 04794d07..3a1d129d 100644
--- a/juick-common/src/main/java/com/juick/service/security/deprecated/RequestParamHashRememberMeServices.java
+++ b/juick-common/src/main/java/com/juick/service/security/deprecated/RequestParamHashRememberMeServices.java
@@ -80,7 +80,7 @@ public class RequestParamHashRememberMeServices extends AbstractRememberMeServic
if (StringUtils.isNotBlank(hash)) {
User user = userService.getUserByHash(hash);
- if (user.getUid() > 0)
+ if (!user.isAnonymous())
return new JuickUser(user);
}
throw new UsernameNotFoundException("User not found by hash " + hash);
diff --git a/juick-server/src/main/java/com/juick/server/MessengerManager.java b/juick-server/src/main/java/com/juick/server/MessengerManager.java
index 51bbb3e2..303e08ce 100644
--- a/juick-server/src/main/java/com/juick/server/MessengerManager.java
+++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java
@@ -78,7 +78,7 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
User user_from = userService.getUserByUID(messengerService.getUserId(senderId)).orElse(new User());
logger.info("Found juick user {}", user_from.getUid());
- if (user_from.getUid() == 0) {
+ if (user_from.isAnonymous()) {
try {
UserProfile profile = messenger.queryUserProfile(senderId);
signupNotify(senderId, messengerService.getSignUpHash(senderId, profile.firstName()));
diff --git a/juick-server/src/main/java/com/juick/server/ServerManager.java b/juick-server/src/main/java/com/juick/server/ServerManager.java
index 92821feb..c3df33cb 100644
--- a/juick-server/src/main/java/com/juick/server/ServerManager.java
+++ b/juick-server/src/main/java/com/juick/server/ServerManager.java
@@ -87,7 +87,7 @@ public class ServerManager implements NotificationListener {
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
- (!c.legacy && c.visitor.getUid() == 0) // anonymous users
+ (!c.legacy && c.visitor.isAnonymous()) // anonymous users
|| c.visitor.getName().equals(serviceUser) // services
|| (!c.legacy && uids.contains(c.visitor.getUid()))) // subscriptions
.forEach(c -> {
@@ -124,7 +124,7 @@ public class ServerManager implements NotificationListener {
.stream().map(User::getUid).collect(Collectors.toList());
synchronized (wsHandler.getClients()) {
wsHandler.getClients().stream().filter(c ->
- (!c.legacy && c.visitor.getUid() == 0) // anonymous users
+ (!c.legacy && c.visitor.isAnonymous()) // anonymous users
|| c.visitor.getName().equals(serviceUser) // services
|| (!c.legacy && threadUsers.contains(c.visitor.getUid()))) // subscriptions
.forEach(c -> {
diff --git a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
index a30b2bf3..c9097cb2 100644
--- a/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/juick-server/src/main/java/com/juick/server/TelegramBotManager.java
@@ -127,7 +127,7 @@ public class TelegramBotManager implements NotificationListener {
telegramService.createTelegramUser(message.from().id(), username);
telegramSignupNotify(message.from().id().longValue(), userService.getSignUpHashByTelegramID(message.from().id().longValue(), username));
} else {
- if (user_from.getUid() == 0) {
+ if (user_from.isAnonymous()) {
telegramSignupNotify(message.from().id().longValue(), userService.getSignUpHashByTelegramID(message.from().id().longValue(), username));
} else {
URI attachment = URI.create(StringUtils.EMPTY);
diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
index 2c21a973..d15db3f2 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
@@ -159,7 +159,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
return iq.createResult(vCard);
}
User user = userService.getUserByName(iq.getTo().getLocal());
- if (user.getUid() > 0) {
+ if (!user.isAnonymous()) {
UserInfo info = userService.getUserInfo(user);
VCard userVCard = new VCard();
userVCard.setFormattedName(info.getFullName());
@@ -546,7 +546,7 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
Jid to = msg.getTo();
if (to.getDomain().equals(router.getDomain().toEscapedString()) || to.equals(this.jid)) {
User user_from = userService.getUserByJID(msg.getFrom().asBareJid().toEscapedString());
- if ((user_from == null || user_from.getUid() == 0) && !msg.getFrom().equals(jid)) {
+ if ((user_from == null || user_from.isAnonymous()) && !msg.getFrom().equals(jid)) {
String signuphash = userService.getSignUpHashByJID(msg.getFrom().asBareJid().toEscapedString());
return makeReply(msg.getFrom(), "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account.");
}
diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java
index 666bab0a..b4d16937 100644
--- a/juick-server/src/main/java/com/juick/server/api/Messages.java
+++ b/juick-server/src/main/java/com/juick/server/api/Messages.java
@@ -93,7 +93,6 @@ public class Messages {
@RequestParam(required = false) String tag) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
List<Integer> mids;
if (!StringUtils.isEmpty(uname)) {
@@ -120,18 +119,18 @@ public class Messages {
}
} else {
if (!StringUtils.isEmpty(popular)) {
- mids = messagesService.getPopular(vuid, before);
+ mids = messagesService.getPopular(visitor.getUid(), before);
} else if (!StringUtils.isEmpty(media)) {
- mids = messagesService.getPhotos(vuid, before);
+ mids = messagesService.getPhotos(visitor.getUid(), before);
} else if (!StringUtils.isEmpty(tag)) {
Tag tagObject = tagService.getTag(tag, false);
if (tagObject != null) {
- mids = messagesService.getTag(tagObject.TID, vuid, before, 20);
+ mids = messagesService.getTag(tagObject.TID, visitor.getUid(), before, 20);
} else {
return NOT_FOUND;
}
} else {
- mids = messagesService.getAll(vuid, before);
+ mids = messagesService.getAll(visitor.getUid(), before);
}
}
return ResponseEntity.ok(messagesService.getMessages(mids));
@@ -145,10 +144,9 @@ public class Messages {
public ResponseEntity<List<com.juick.Message>> getThread(
@RequestParam(defaultValue = "0") int mid) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
com.juick.Message msg = messagesService.getMessage(mid);
if (msg != null) {
- if (!messagesService.canViewThread(mid, vuid)) {
+ if (!messagesService.canViewThread(mid, visitor.getUid())) {
return FORBIDDEN;
} else {
List<com.juick.Message> replies = messagesService.getReplies(visitor, mid);
@@ -162,7 +160,7 @@ public class Messages {
@GetMapping(value = "/thread/mark_read/{mid}-{rid}.gif", produces = MediaType.IMAGE_GIF_VALUE)
public byte[] markThreadRead(@PathVariable int mid, @PathVariable int rid) throws IOException {
User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() > 0) {
+ if (!visitor.isAnonymous()) {
messagesService.setLastReadComment(visitor, mid, rid);
Message msg = messagesService.getMessage(mid);
applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg));
diff --git a/juick-server/src/main/java/com/juick/server/api/Notifications.java b/juick-server/src/main/java/com/juick/server/api/Notifications.java
index 5c7cf7b9..e068cbe9 100644
--- a/juick-server/src/main/java/com/juick/server/api/Notifications.java
+++ b/juick-server/src/main/java/com/juick/server/api/Notifications.java
@@ -73,7 +73,7 @@ public class Notifications {
@RequestParam(required = false, defaultValue = "0") int mid,
@RequestParam(required = false, defaultValue = "0") int rid) {
User visitor = UserUtils.getCurrentUser();
- if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
+ if (visitor.isAnonymous() || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
if (uid > 0 && mid == 0) {
@@ -106,7 +106,7 @@ public class Notifications {
@RequestBody List<ExternalToken> list) {
User visitor = UserUtils.getCurrentUser();
// FIXME: it is possible to delete other user's tokens
- if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
+ if ((visitor.isAnonymous()) || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
list.forEach(t -> {
@@ -133,7 +133,7 @@ public class Notifications {
public Status doPut(
@RequestBody List<ExternalToken> list) throws IOException {
User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
list.forEach(t -> {
@@ -159,7 +159,7 @@ public class Notifications {
public Status doAndroidRegister(
@RequestParam(name = "regid") String regId) {
User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
pushQueriesService.addGCMToken(visitor.getUid(), regId);
diff --git a/juick-server/src/main/java/com/juick/server/api/PM.java b/juick-server/src/main/java/com/juick/server/api/PM.java
index 3649bb5e..045d465e 100644
--- a/juick-server/src/main/java/com/juick/server/api/PM.java
+++ b/juick-server/src/main/java/com/juick/server/api/PM.java
@@ -51,8 +51,7 @@ public class PM {
public List<com.juick.Message> doGetPM(
@RequestParam(required = false) String uname) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
int uid = 0;
@@ -64,7 +63,7 @@ public class PM {
throw new HttpBadRequestException();
}
- return pmQueriesService.getPMMessages(vuid, uid);
+ return pmQueriesService.getPMMessages(visitor.getUid(), uid);
}
@RequestMapping(value = "/pm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@@ -72,8 +71,7 @@ public class PM {
@RequestParam String uname,
@RequestParam String body) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
User userTo = AnonymousUser.INSTANCE;
@@ -85,11 +83,11 @@ public class PM {
throw new HttpBadRequestException();
}
- if (userService.isInBLAny(userTo.getUid(), vuid)) {
+ if (userService.isInBLAny(userTo.getUid(), visitor.getUid())) {
throw new HttpForbiddenException();
}
- if (pmQueriesService.createPM(vuid, userTo.getUid(), body)) {
+ if (pmQueriesService.createPM(visitor.getUid(), userTo.getUid(), body)) {
com.juick.Message jmsg = new com.juick.Message();
jmsg.setUser(visitor);
jmsg.setText(body);
@@ -104,8 +102,7 @@ public class PM {
public PrivateChats doGetGroupsPMs(
@RequestParam(defaultValue = "5") int cnt) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
if (cnt < 3) {
@@ -115,7 +112,7 @@ public class PM {
cnt = 10;
}
- List<User> lastconv = pmQueriesService.getPMLastConversationsUsers(vuid, cnt);
+ List<User> lastconv = pmQueriesService.getPMLastConversationsUsers(visitor.getUid(), cnt);
if (lastconv != null && !lastconv.isEmpty()) {
PrivateChats pms = new PrivateChats();
pms.setUsers(lastconv);
diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java
index 8b273354..3e546eac 100644
--- a/juick-server/src/main/java/com/juick/server/api/Users.java
+++ b/juick-server/src/main/java/com/juick/server/api/Users.java
@@ -69,13 +69,12 @@ public class Users {
public List<User> doGetUserRead(
@RequestParam String uname) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
int uid = 0;
if (uname == null) {
- uid = vuid;
+ uid = visitor.getUid();
} else {
if (WebUtils.isUserName(uname)) {
com.juick.User u = userService.getUserByName(uname);
@@ -101,13 +100,12 @@ public class Users {
public List<User> doGetUserReaders(
@RequestParam String uname) {
User visitor = UserUtils.getCurrentUser();
- int vuid = visitor.getUid();
- if (vuid == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpForbiddenException();
}
int uid = 0;
if (uname == null) {
- uid = vuid;
+ uid = visitor.getUid();
} else {
if (WebUtils.isUserName(uname)) {
com.juick.User u = userService.getUserByName(uname);
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java b/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
index a2d44500..d2d112d8 100644
--- a/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
+++ b/juick-server/src/main/java/com/juick/server/api/rss/Feeds.java
@@ -45,7 +45,7 @@ public class Feeds {
@RequestMapping(value = "/rss/{userName}/blog", method = RequestMethod.GET)
public ModelAndView getBlog(@PathVariable String userName) {
User user = userService.getUserByName(userName);
- if (user.getUid() > 0) {
+ if (!user.isAnonymous()) {
List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, 0);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("messagesView");
diff --git a/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java b/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
index e5d2ec3f..52e748f0 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/AnythingFilter.java
@@ -52,7 +52,7 @@ public class AnythingFilter implements Filter {
}
} else {
com.juick.User user = userService.getUserByName(anything);
- if (user.getUid() > 0) {
+ if (!user.isAnonymous()) {
((HttpServletResponse) servletResponse).sendRedirect("/" + user.getName() + "/?before=" + before);
} else {
filterChain.doFilter(servletRequest, servletResponse);
diff --git a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
index 01efd6c9..033404b6 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/MessagesWWW.java
@@ -112,7 +112,7 @@ public class MessagesWWW {
title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch);
mids = messagesService.getSearch(Utils.encodeSphinx(paramSearch), paramBefore);
} else if (paramShow == null) {
- if (visitor.getUid() > 0) {
+ if (!visitor.isAnonymous()) {
title = "Популярные";
mids = messagesService.getPopular(visitor.getUid(), paramBefore);
model.addAttribute("discover", true);
@@ -157,7 +157,7 @@ public class MessagesWWW {
model.addAttribute("noindex", !(paramShow == null && paramBefore == 0));
List<com.juick.Message> msgs = messagesService.getMessages(mids);
- if (visitor.getUid() != 0) {
+ if (!visitor.isAnonymous()) {
fillUserModel(model, visitor, visitor);
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
@@ -172,7 +172,7 @@ public class MessagesWWW {
model.addAttribute("tags", tagService.getPopularTags());
model.addAttribute("headers", head);
model.addAttribute("showAdv",
- paramShow == null && paramBefore == 0 && paramSearch == null && visitor.getUid() == 0);
+ paramShow == null && paramBefore == 0 && paramSearch == null && visitor.isAnonymous());
if (mids.size() >= 20) {
String nextpage = (paramShow != null && paramShow.equals("discuss")) ? "?to=" + msgs.get(msgs.size() - 1).getUpdated().toEpochMilli() : "?before=" + mids.get(mids.size() - 1);
if (paramShow != null) {
@@ -186,7 +186,7 @@ public class MessagesWWW {
UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
String queryString = builder.getQuery();
String requestURI = builder.toUri().getPath();
- if (sape != null && visitor.getUid() == 0 && queryString == null) {
+ if (sape != null && visitor.isAnonymous() && queryString == null) {
String links = sape.getPageLinks(requestURI, sapeCookie).render();
model.addAttribute("links", links);
}
@@ -227,7 +227,7 @@ public class MessagesWWW {
}
int privacy = 0;
- if (visitor.getUid() > 0) {
+ if (!visitor.isAnonymous()) {
if (user.getUid() == visitor.getUid() || visitor.getUid() == 1) {
privacy = -3;
} else if (userService.isInWL(user.getUid(), visitor.getUid())) {
@@ -273,7 +273,7 @@ public class MessagesWWW {
model.addAttribute("paramTag", paramTag);
List<com.juick.Message> msgs = messagesService.getMessages(mids);
- if (visitor.getUid() != 0) {
+ if (!visitor.isAnonymous()) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
@@ -303,7 +303,7 @@ public class MessagesWWW {
UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
String queryString = builder.getQuery();
String requestURI = builder.toUri().getPath();
- if (sape != null && visitor.getUid() == 0 && queryString == null) {
+ if (sape != null && visitor.isAnonymous() && queryString == null) {
String links = sape.getPageLinks(requestURI, sapeCookie).render();
model.addAttribute("links", links);
}
@@ -402,13 +402,11 @@ public class MessagesWWW {
return "redirect:" + url;
}
- int visitor_uid = visitor.getUid();
-
String title = "*" + StringEscapeUtils.escapeHtml4(paramTag.getName());
model.addAttribute("title", title);
- List<Integer> mids = messagesService.getTag(paramTag.TID, visitor_uid, before, (visitor_uid == 0) ? 40 : 20);
+ List<Integer> mids = messagesService.getTag(paramTag.TID, visitor.getUid(), before, (visitor.isAnonymous()) ? 40 : 20);
List<com.juick.Message> msgs = messagesService.getMessages(mids);
- if (visitor.getUid() != 0) {
+ if (!visitor.isAnonymous()) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
List<Integer> blUIDs = userService.checkBL(
@@ -435,7 +433,7 @@ public class MessagesWWW {
model.addAttribute("msgs", msgs);
model.addAttribute("tags", tagService.getPopularTags());
model.addAttribute("noindex", before > 0);
- model.addAttribute("showAdv", before == 0 && visitor.getUid() == 0);
+ model.addAttribute("showAdv", before == 0 && visitor.isAnonymous());
model.addAttribute("isSubscribed", tagService.isSubscribed(visitor, paramTag));
model.addAttribute("isInBL", tagService.isInBL(visitor, paramTag));
if (mids.size() >= 20) {
@@ -445,7 +443,7 @@ public class MessagesWWW {
UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
String queryString = builder.getQuery();
String requestURI = builder.toUri().getPath();
- if (sape != null && visitor.getUid() == 0 && queryString == null) {
+ if (sape != null && visitor.isAnonymous() && queryString == null) {
String links = sape.getPageLinks(requestURI, sapeCookie).render();
model.addAttribute("links", links);
}
@@ -454,7 +452,7 @@ public class MessagesWWW {
@GetMapping("/pm/inbox")
protected String doGetInbox(ModelMap model) {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
return "redirect:/login";
}
String title = "PM: Inbox";
@@ -471,7 +469,7 @@ public class MessagesWWW {
protected String doGetSent(@RequestParam(required = false) String uname,
ModelMap model) {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
return "redirect:/login";
}
String title = "PM: Sent";
@@ -507,19 +505,17 @@ public class MessagesWWW {
}
com.juick.User user = userService.getUserByName(uname);
- if (user.getUid() == 0 || !msg.getUser().equals(user)) {
+ if (user.isAnonymous() || !msg.getUser().equals(user)) {
return String.format("redirect:/%s/%d", msg.getUser().getName(), mid);
}
- msg.VisitorCanComment = visitor.getUid() > 0;
+ msg.VisitorCanComment = !visitor.isAnonymous();
List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid());
- if (!visitor.isAnonymous()) {
- applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg));
- }
// this should be after getReplies to mark thread as read
fillUserModel(model, user, visitor);
- if (visitor.getUid() > 0) {
+ if (!visitor.isAnonymous()) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
+ applicationEventPublisher.publishEvent(new MessageReadEvent(this, visitor, msg));
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isInBL = userService.isInBLAny(msg.getUser().getUid(), visitor.getUid());
msg.VisitorCanComment = isMsgAuthor || !(msg.ReadOnly || isInBL);
@@ -572,8 +568,8 @@ public class MessagesWWW {
&& !blUIDs.contains(reply.getUser().getUid())) {
blUIDs.add(reply.getUser().getUid());
}
- reply.VisitorCanComment = visitor.getUid() > 0;
- if (visitor.getUid() > 0) {
+ reply.VisitorCanComment = !visitor.isAnonymous();
+ if (!visitor.isAnonymous()) {
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid();
reply.VisitorCanComment = isMsgAuthor || (!msg.ReadOnly
@@ -581,11 +577,11 @@ public class MessagesWWW {
}
}
model.addAttribute("replies", replies);
- model.addAttribute("showAdv", visitor.getUid() == 0);
+ model.addAttribute("showAdv", visitor.isAnonymous());
UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
String queryString = builder.getQuery();
String requestURI = builder.toUri().getPath();
- if (sape != null && visitor.getUid() == 0 && queryString == null) {
+ if (sape != null && visitor.isAnonymous() && queryString == null) {
String links = sape.getPageLinks(requestURI, sapeCookie).render();
model.addAttribute("links", links);
}
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index 1b3db61d..a464add2 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -115,7 +115,7 @@ public class NewMessage {
@RequestParam(required = false, defaultValue = StringUtils.EMPTY) String img,
@RequestParam(required = false) MultipartFile attach) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0 || visitor.isBanned()) {
+ if (visitor.isAnonymous() || visitor.isBanned()) {
throw new HttpForbiddenException();
}
com.juick.Message msg = messagesService.getMessage(mid);
@@ -177,7 +177,7 @@ public class NewMessage {
public String doPostPM(@RequestParam(name = "uname", required = false) String unameParam,
@RequestParam String body) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0 || visitor.isBanned()) {
+ if (visitor.isAnonymous() || visitor.isBanned()) {
throw new HttpForbiddenException();
}
String uname = unameParam;
@@ -189,7 +189,7 @@ public class NewMessage {
userTo = userService.getUserByName(uname);
}
- if (userTo.getUid() == 0 || body.length() > 10240) {
+ if (userTo.isAnonymous() || body.length() > 10240) {
throw new HttpBadRequestException();
}
@@ -218,7 +218,7 @@ public class NewMessage {
@RequestParam(required = false) MultipartFile attach) throws JsonProcessingException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0 || visitor.isBanned()) {
+ if (visitor.isAnonymous() || visitor.isBanned()) {
throw new HttpForbiddenException();
}
String body = StringUtils.isNotEmpty(bodyParam) ? bodyParam.replace("\r", StringUtils.EMPTY) : StringUtils.EMPTY;
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
index 3d381815..7f6cce44 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
@@ -82,7 +82,7 @@ public class Settings {
@GetMapping("/settings")
protected String doGet(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
response.sendRedirect("/login");
}
List<String> pages = Arrays.asList("main", "password", "about", "auth-email", "privacy");
@@ -124,7 +124,7 @@ public class Settings {
ModelMap model)
throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
throw new HttpBadRequestException();
}
List<String> pages = Arrays.asList("main", "password", "about", "email", "email-add", "email-del",
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
index a5851215..02a8006b 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/SignUp.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/SignUp.java
@@ -103,7 +103,7 @@ public class SignUp {
if (action.charAt(0) == 'l') {
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
if (username.length() > 32) {
throw new HttpBadRequestException();
}
@@ -145,7 +145,7 @@ public class SignUp {
}
}
- if (visitor.getUid() == 0) {
+ if (visitor.isAnonymous()) {
hash = userService.getHashByUID(uid);
Cookie c = new Cookie("hash", hash);
c.setMaxAge(365 * 24 * 60 * 60);