aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/juick/api/Users.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/juick/api/Users.java')
-rw-r--r--src/java/com/juick/api/Users.java46
1 files changed, 44 insertions, 2 deletions
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;
}