aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2013-07-22 03:44:01 +0700
committerGravatar Ugnich Anton2013-07-22 03:44:01 +0700
commit4b1ef499dbd28c1639b9723ee2e9c5ff80002dde (patch)
treee96c774f4e54f23ca03f71c4b63a64cba86232ad
parentdf529650d03296bf03ade8c0eed4a2fcc404a041 (diff)
/users/
-rw-r--r--nbproject/build-impl.xml2
-rw-r--r--nbproject/genfiles.properties6
-rw-r--r--nbproject/project.properties4
-rw-r--r--nbproject/project.xml8
-rw-r--r--src/java/com/juick/api/Main.java4
-rw-r--r--src/java/com/juick/api/Users.java46
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:
<copyfiles files="${reference.com_juick.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${reference.com_juick_server.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${reference.com_juick_json.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
+ <copyfiles files="${libs.JSON.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
@@ -703,6 +704,7 @@ exists or setup the property manually. For example like this:
<copyfiles files="${reference.com_juick.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${reference.com_juick_server.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${reference.com_juick_json.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
+ <copyfiles files="${libs.JSON.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
</target>
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/>
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 @@
<file>${reference.com_juick_json.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
+ <library dirs="200">
+ <file>${libs.JSON.classpath}</file>
+ <path-in-war>WEB-INF/lib</path-in-war>
+ </library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
- <root id="src.dir" name="Source Packages"/>
+ <root id="src.dir"/>
</source-roots>
<test-roots>
- <root id="test.src.dir" name="Test Packages"/>
+ <root id="test.src.dir"/>
</test-roots>
</data>
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
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;
}