From 4b1ef499dbd28c1639b9723ee2e9c5ff80002dde Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Mon, 22 Jul 2013 03:44:01 +0700
Subject: /users/
---
nbproject/build-impl.xml | 2 ++
nbproject/genfiles.properties | 6 ++---
nbproject/project.properties | 4 ++--
nbproject/project.xml | 8 +++++--
src/java/com/juick/api/Main.java | 4 +++-
src/java/com/juick/api/Users.java | 46 +++++++++++++++++++++++++++++++++++++--
6 files changed, 60 insertions(+), 10 deletions(-)
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
index c6dd50e7..965b7552 100644
--- a/nbproject/build-impl.xml
+++ b/nbproject/build-impl.xml
@@ -696,6 +696,7 @@ exists or setup the property manually. For example like this:
+
@@ -703,6 +704,7 @@ exists or setup the property manually. For example like this:
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index 0b047451..13678348 100644
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=649ef84a
+build.xml.data.CRC32=8cb2a940
build.xml.script.CRC32=2226508e
build.xml.stylesheet.CRC32=651128d4@1.33.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=649ef84a
-nbproject/build-impl.xml.script.CRC32=3499afe6
+nbproject/build-impl.xml.data.CRC32=8cb2a940
+nbproject/build-impl.xml.script.CRC32=9918d740
nbproject/build-impl.xml.stylesheet.CRC32=0cbf5bb7@1.33.1.1
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 5d65b1aa..e57401a6 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -36,7 +36,8 @@ jar.compress=false
javac.classpath=\
${reference.com_juick.jar}:\
${reference.com_juick_server.jar}:\
- ${reference.com_juick_json.jar}
+ ${reference.com_juick_json.jar}:\
+ ${libs.JSON.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
@@ -63,7 +64,6 @@ javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web.docbase.dir}/WEB-INF/lib
-no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
project.com_juick=../com.juick
diff --git a/nbproject/project.xml b/nbproject/project.xml
index 6d66c021..15c691a1 100644
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -18,13 +18,17 @@
${reference.com_juick_json.jar}
WEB-INF/lib
+
+ ${libs.JSON.classpath}
+ WEB-INF/lib
+
-
+
-
+
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 users = new ArrayList();
+
+ String punames[] = request.getParameterValues("uname");
+ if (punames != null) {
+ ArrayList unames = new ArrayList(Arrays.asList(punames));
+ Iterator 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 jids = new ArrayList(Arrays.asList(pjids));
+ Iterator 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;
}
--
cgit v1.2.3