diff options
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
5 files changed, 22 insertions, 29 deletions
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"); |