diff options
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/juick/api/Main.java | 4 | ||||
-rw-r--r-- | src/java/com/juick/api/Users.java | 46 |
2 files changed, 47 insertions, 3 deletions
diff --git a/src/java/com/juick/api/Main.java b/src/java/com/juick/api/Main.java index ebbeb103..449c2a86 100644 --- a/src/java/com/juick/api/Main.java +++ b/src/java/com/juick/api/Main.java @@ -95,7 +95,9 @@ public class Main extends HttpServlet { int vuid = Utils.getHttpAuthUID(sql, request); String uri = request.getRequestURI(); - if (uri.equals("/users/read")) { + if (uri.equals("/users")) { + users.doGetUsers(request, response, vuid); + } else if (uri.equals("/users/read")) { users.doGetUserRead(request, response, vuid); } else if (uri.equals("/users/readers")) { users.doGetUserReaders(request, response, vuid); diff --git a/src/java/com/juick/api/Users.java b/src/java/com/juick/api/Users.java index 2c60a95f..cdd48fd6 100644 --- a/src/java/com/juick/api/Users.java +++ b/src/java/com/juick/api/Users.java @@ -1,9 +1,12 @@ package com.juick.api; +import com.juick.User; import com.juick.server.UserQueries; import java.io.IOException; import java.sql.Connection; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -20,6 +23,45 @@ public class Users { this.sql = sql; } + public void doGetUsers(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { + ArrayList<com.juick.User> users = new ArrayList<User>(); + + String punames[] = request.getParameterValues("uname"); + if (punames != null) { + ArrayList<String> unames = new ArrayList<String>(Arrays.asList(punames)); + Iterator<String> i = unames.iterator(); + while (i.hasNext()) { + if (!i.next().matches("^[a-zA-Z0-9\\-]{2,16}$")) { + i.remove(); + } + } + if (!unames.isEmpty() && unames.size() < 20) { + users.addAll(UserQueries.getUsersByName(sql, unames)); + } + } + + String pjids[] = request.getParameterValues("jid"); + if (pjids != null) { + ArrayList<String> jids = new ArrayList<String>(Arrays.asList(pjids)); + Iterator<String> ii = jids.iterator(); + while (ii.hasNext()) { + if (!ii.next().matches("^[a-zA-Z0-9\\-\\_\\@\\.]{6,64}$")) { + ii.remove(); + } + } + if (!jids.isEmpty() && jids.size() < 20) { + users.addAll(UserQueries.getUsersByJID(sql, jids)); + } + } + + if (!users.isEmpty()) { + String json = com.juick.json.Users.arrayToString(users); + Main.replyJSON(request, response, json); + } else { + response.sendError(404); + } + } + public void doGetUserRead(HttpServletRequest request, HttpServletResponse response, int vuid) throws ServletException, IOException { int uid = 0; String uname = request.getParameter("uname"); @@ -27,7 +69,7 @@ public class Users { uid = vuid; } else { if (UserQueries.checkUserNameValid(uname)) { - com.juick.User u = UserQueries.getUserByNick(sql, uname); + com.juick.User u = UserQueries.getUserByName(sql, uname); if (u != null && u.UID > 0) { uid = u.UID; } @@ -55,7 +97,7 @@ public class Users { uid = vuid; } else { if (UserQueries.checkUserNameValid(uname)) { - com.juick.User u = UserQueries.getUserByNick(sql, uname); + com.juick.User u = UserQueries.getUserByName(sql, uname); if (u != null && u.UID > 0) { uid = u.UID; } |