diff options
author | Vitaly Takmazov | 2016-11-24 21:38:52 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-24 23:26:57 +0300 |
commit | d233943fc29508dc37714852b11b96b0b46b55d9 (patch) | |
tree | 129cd564c021261247e72ac70605c1e559c6dac4 /juick-api/src/main/java/com/juick/api/Users.java | |
parent | bcd9ae221522fa779ea1fd1ff1ab5b561ca0895f (diff) |
juick-api: now on spring-webmvc
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/Users.java')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/Users.java | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/juick-api/src/main/java/com/juick/api/Users.java b/juick-api/src/main/java/com/juick/api/Users.java deleted file mode 100644 index 04e53346..00000000 --- a/juick-api/src/main/java/com/juick/api/Users.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.juick.api; - -import com.juick.User; -import com.juick.json.UserSerializer; -import com.juick.server.UserQueries; -import com.juick.util.UserUtils; -import org.springframework.jdbc.core.JdbcTemplate; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * - * @author ugnich - */ -public class Users { - - JdbcTemplate sql; - - UserSerializer userSerializer = new UserSerializer(); - - public Users(JdbcTemplate sql) { - this.sql = sql; - } - - public void doGetUsers(HttpServletRequest request, - HttpServletResponse response, int vuid) - throws ServletException, IOException { - List<com.juick.User> users = new ArrayList<>(); - - String punames[] = request.getParameterValues("uname"); - if (punames != null) { - ArrayList<String> unames = new ArrayList<>(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) { - List<String> jids = new ArrayList<>(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 = userSerializer.serializeList(users); - Main.replyJSON(request, response, json); - } else { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } - } - - public void doGetUserRead(HttpServletRequest request, - HttpServletResponse response, int vuid) - throws ServletException, IOException { - int uid = 0; - String uname = request.getParameter("uname"); - if (uname == null) { - uid = vuid; - } else { - if (UserUtils.checkUserNameValid(uname)) { - com.juick.User u = UserQueries.getUserByName(sql, uname); - if (u != null && u.getUid() > 0) { - uid = u.getUid(); - } - } - } - - if (uid > 0) { - List<Integer> uids = UserQueries.getUserRead(sql, uid); - if (uids.size() > 0) { - List<com.juick.User> users = UserQueries.getUsersByID(sql, uids); - if (users.size() > 0) { - String json = userSerializer.serializeList(users); - Main.replyJSON(request, response, json); - return; - } - } - } - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } - - public void doGetUserReaders(HttpServletRequest request, - HttpServletResponse response, int vuid) - throws ServletException, IOException { - int uid = 0; - String uname = request.getParameter("uname"); - if (uname == null) { - uid = vuid; - } else { - if (UserUtils.checkUserNameValid(uname)) { - com.juick.User u = UserQueries.getUserByName(sql, uname); - if (u != null && u.getUid() > 0) { - uid = u.getUid(); - } - } - } - - if (uid > 0) { - List<User> users = UserQueries.getUserReaders(sql, uid); - String json = userSerializer.serializeList(users); - Main.replyJSON(request, response, json); - return; - } - response.sendError(HttpServletResponse.SC_NOT_FOUND); - } -} |