From 0f0df74a6a0b069eabbf788d754389ee4c396f84 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Jun 2018 14:04:59 +0300 Subject: move hash to /me endpoint --- .../src/main/java/com/juick/server/api/Users.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'juick-server/src/main/java') 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 2783e9bc..4e447d04 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 @@ -61,14 +61,22 @@ public class Users { if (!users.isEmpty()) return users; if (!UserUtils.getCurrentUser().isAnonymous()) { - com.juick.User visitor = UserUtils.getCurrentUser(); - visitor.setAuthHash(getAuthToken()); - return Collections.singletonList(visitor); + return Collections.singletonList(UserUtils.getCurrentUser()); } throw new HttpNotFoundException(); } + @GetMapping("/me") + public SecureUser getMe() { + User visitor = UserUtils.getCurrentUser(); + SecureUser me = new SecureUser(); + me.setUid(visitor.getUid()); + me.setName(visitor.getName()); + me.setAuthHash(getAuthToken()); + return me; + } + @RequestMapping(value = "/users/read", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public List doGetUserRead( @RequestParam String uname) { @@ -124,4 +132,10 @@ public class Users { } throw new HttpNotFoundException(); } + + class SecureUser extends User { + public String getHash() { + return getAuthHash(); + } + } } -- cgit v1.2.3