mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
Merge branch 'release/2.0'
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,5 +9,4 @@ out/
|
||||
.DS_Store
|
||||
.classpath
|
||||
/target
|
||||
/src/main/webapp/META-INF/context.xml
|
||||
.project
|
||||
316
pom.xml
316
pom.xml
@@ -1,162 +1,168 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>WechatTicketSystem</name>
|
||||
<groupId>love.sola.netsupport</groupId>
|
||||
<artifactId>WechatTicketSystem</artifactId>
|
||||
<version>1.4-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>WechatTicketSystem</name>
|
||||
<groupId>love.sola.netsupport</groupId>
|
||||
<artifactId>WechatTicketSystem</artifactId>
|
||||
<version>2.0</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:svn:http://127.0.0.1/dummy</connection>
|
||||
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<url>http://127.0.0.1/dummy</url>
|
||||
</scm>
|
||||
<scm>
|
||||
<connection>scm:svn:http://127.0.0.1/dummy</connection>
|
||||
<developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<url>http://127.0.0.1/dummy</url>
|
||||
</scm>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<configuration>
|
||||
<format>{0,number,0000}</format>
|
||||
<items>
|
||||
<item>buildNumber0</item>
|
||||
</items>
|
||||
<doCheck>false</doCheck>
|
||||
<doUpdate>false</doUpdate>
|
||||
<revisionOnScmFailure>unknown</revisionOnScmFailure>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}##${buildNumber}</finalName>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<configuration>
|
||||
<format>{0,number,0000}</format>
|
||||
<items>
|
||||
<item>buildNumber0</item>
|
||||
</items>
|
||||
<doCheck>false</doCheck>
|
||||
<doUpdate>false</doUpdate>
|
||||
<revisionOnScmFailure>unknown</revisionOnScmFailure>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}##${buildNumber}</finalName>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0-rc2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
<version>0.9.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.37</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-c3p0</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||
<version>1.0.0.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-envers</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.svenkubiak</groupId>
|
||||
<artifactId>jBCrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0-rc2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mchange</groupId>
|
||||
<artifactId>c3p0</artifactId>
|
||||
<version>0.9.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.37</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-c3p0</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||
<version>1.0.0.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-envers</artifactId>
|
||||
<version>5.0.3.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.svenkubiak</groupId>
|
||||
<artifactId>jBCrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,34 +0,0 @@
|
||||
package love.sola.netsupport;
|
||||
|
||||
import love.sola.netsupport.util.RSAUtil;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.format;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/12.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
|
||||
@WebServlet(name = "LoginRedirect", urlPatterns = "/login", loadOnStartup = 2)
|
||||
public class Login extends HttpServlet {
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.sendRedirect(format("Operator_Login_Page", RSAUtil.publicKey_s));
|
||||
}
|
||||
|
||||
}
|
||||
32
src/main/java/love/sola/netsupport/api/API.java
Normal file
32
src/main/java/love/sola/netsupport/api/API.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2016/2/27.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public abstract class API {
|
||||
|
||||
public String url = null; //url
|
||||
public int access = Access.GOD_MODE; //operator's permission
|
||||
public Command authorize = null; //session check
|
||||
|
||||
protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{" +
|
||||
"url='" + url + '\'' +
|
||||
", access=" + Access.inverseMap.get(access) +
|
||||
", authorize=" + authorize +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
126
src/main/java/love/sola/netsupport/api/APIRouter.java
Normal file
126
src/main/java/love/sola/netsupport/api/APIRouter.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2016/2/27.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "APIRouter", urlPatterns = "/api/*", loadOnStartup = 11)
|
||||
public class APIRouter extends HttpServlet {
|
||||
|
||||
protected static Gson gson = SQLCore.gson;
|
||||
private Map<String, API> nodes = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
try {
|
||||
Reflections reflections = new Reflections(getClass().getPackage().getName());
|
||||
Set<Class<? extends API>> set = reflections.getSubTypesOf(API.class);
|
||||
for (Class<? extends API> clz : set) {
|
||||
try {
|
||||
System.out.println("Loading API: " + clz.getName());
|
||||
API obj = clz.newInstance();
|
||||
System.out.println("Registered API: " + obj);
|
||||
nodes.put(obj.url, obj);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Total " + nodes.size() + " API(s) loaded.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.setCharacterEncoding("utf-8");
|
||||
resp.setCharacterEncoding("utf-8");
|
||||
resp.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
resp.addHeader("Access-Control-Allow-Origin", "*");
|
||||
Object obj = null;
|
||||
try {
|
||||
API api = nodes.get(req.getPathInfo());
|
||||
if (api == null) {
|
||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
WxSession session = getSession(req);
|
||||
if (session == null) {
|
||||
obj = Error.UNAUTHORIZED;
|
||||
return;
|
||||
}
|
||||
if (api.authorize != null) {
|
||||
if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
|
||||
obj = Error.UNAUTHORIZED;
|
||||
return;
|
||||
}
|
||||
if (api.access == Access.USER) {
|
||||
User u = session.getAttribute(Attribute.USER);
|
||||
if (u == null) {
|
||||
obj = Error.UNAUTHORIZED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (api.access < Access.USER) {
|
||||
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||
if (op == null) {
|
||||
obj = Error.UNAUTHORIZED;
|
||||
return;
|
||||
}
|
||||
if (op.getAccess() > api.access) {
|
||||
obj = Error.PERMISSION_DENIED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
obj = api.process(req, session);
|
||||
} catch (ParseException | NumberFormatException e) {
|
||||
obj = Error.ILLEGAL_PARAMETER;
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
obj = Error.DATABASE_ERROR;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
obj = Error.INTERNAL_ERROR;
|
||||
} finally {
|
||||
if (!resp.isCommitted()) {
|
||||
try (PrintWriter out = resp.getWriter()) {
|
||||
out.println(gson.toJson(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static WxSession getSession(HttpServletRequest req) {
|
||||
String t = req.getParameter("token");
|
||||
if (t == null || t.isEmpty()) return null;
|
||||
return WechatSession.get(t);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,10 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -23,44 +14,28 @@ import java.util.Map;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "CheckSession", urlPatterns = "/api/checksession", loadOnStartup = 11)
|
||||
public class CheckSession extends HttpServlet {
|
||||
public class CheckSession extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public CheckSession() {
|
||||
url = "/checksession";
|
||||
access = Access.GUEST;
|
||||
authorize = null;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(check(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response check(HttpServletRequest request) {
|
||||
String t = request.getParameter("token");
|
||||
if (t == null || t.isEmpty()) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
WxSession s = WechatSession.get(t, false);
|
||||
if (s == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
String more = request.getParameter("more");
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String more = req.getParameter("more");
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(Attribute.AUTHORIZED, s.getAttribute(Attribute.AUTHORIZED));
|
||||
if (more != null){
|
||||
result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
|
||||
if (more != null) {
|
||||
switch (more) {
|
||||
case "1":
|
||||
result.put(Attribute.USER, s.getAttribute(Attribute.USER));
|
||||
result.put(Attribute.OPERATOR, s.getAttribute(Attribute.OPERATOR));
|
||||
result.put(Attribute.USER, session.getAttribute(Attribute.USER));
|
||||
result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Response(Response.ResponseCode.OK, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
45
src/main/java/love/sola/netsupport/api/Error.java
Normal file
45
src/main/java/love/sola/netsupport/api/Error.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/5.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class Error {
|
||||
|
||||
public static final Error ALREADY_SUBMITTED = new Error(1);
|
||||
public static final Object OK = new Object();
|
||||
public static final Error PARAMETER_REQUIRED = new Error(-1);
|
||||
public static final Error ILLEGAL_PARAMETER = new Error(-2);
|
||||
// public static final Error REQUEST_FAILED = new Error(-3); REMOVED
|
||||
public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
|
||||
public static final Error INVALID_PARAMETER = new Error(-5);
|
||||
public static final Error USER_NOT_FOUND = new Error(-11);
|
||||
public static final Error TICKET_NOT_FOUND = new Error(-12);
|
||||
public static final Error OPERATOR_NOT_FOUND = new Error(-13);
|
||||
public static final Error UNAUTHORIZED = new Error(-20);
|
||||
public static final Error WRONG_PASSWORD = new Error(-22);
|
||||
public static final Error PERMISSION_DENIED = new Error(-24);
|
||||
public static final Error INTERNAL_ERROR = new Error(-90);
|
||||
public static final Error DATABASE_ERROR = new Error(-91);
|
||||
|
||||
public int errCode;
|
||||
public String errMsg;
|
||||
|
||||
private Error(int code) {
|
||||
this(code, lang("ERR_" + code));
|
||||
}
|
||||
|
||||
public Error(int errCode, String errMsg) {
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public Error withMsg(String msg) {
|
||||
return new Error(errCode, msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,15 +5,14 @@ import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.sql.TableOperator;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Crypto;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.util.RSAUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
@@ -43,29 +42,28 @@ public class Login extends HttpServlet {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(login(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.println(gson.toJson(login(request)));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response login(HttpServletRequest request) {
|
||||
private Object login(HttpServletRequest request) {
|
||||
try {
|
||||
int oid = Integer.parseInt(request.getParameter("id"));
|
||||
String password = request.getParameter("pass");
|
||||
boolean bypass = request.getParameter("bypass") != null;
|
||||
Operator op = TableOperator.get(oid);
|
||||
if (op == null)
|
||||
return new Response(Response.ResponseCode.OPERATOR_NOT_FOUND);
|
||||
else if (op.getAccess() == Access.NOLOGIN)
|
||||
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||
return Error.OPERATOR_NOT_FOUND;
|
||||
else if (op.getAccess() >= Access.NO_LOGIN)
|
||||
return Error.PERMISSION_DENIED;
|
||||
|
||||
if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) {
|
||||
return new Response(Response.ResponseCode.WRONG_PASSWORD);
|
||||
return Error.WRONG_PASSWORD;
|
||||
}
|
||||
|
||||
String sid = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(sid, true);
|
||||
WxSession session = WechatSession.create();
|
||||
if (bypass) {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
|
||||
} else {
|
||||
@@ -83,10 +81,10 @@ public class Login extends HttpServlet {
|
||||
if (request.getParameter("bypasswechat") != null) {
|
||||
session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
|
||||
}
|
||||
|
||||
return new Response(Response.ResponseCode.OK, sid);
|
||||
return session.getId();
|
||||
} catch (Exception e) {
|
||||
return new Response(Response.ResponseCode.REQUEST_FAILED, e);
|
||||
e.printStackTrace();
|
||||
return Error.INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/5.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class Response {
|
||||
|
||||
public int code;
|
||||
public String info;
|
||||
public Object result;
|
||||
|
||||
public Response(ResponseCode code) {
|
||||
this(code, null);
|
||||
}
|
||||
|
||||
public Response(ResponseCode code, Object result) {
|
||||
this.code = code.id;
|
||||
this.info = code.name();
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
public enum ResponseCode {
|
||||
|
||||
ALREADY_SUBMITTED(1),
|
||||
OK(0),
|
||||
PARAMETER_REQUIRED(-1),
|
||||
ILLEGAL_PARAMETER(-2),
|
||||
REQUEST_FAILED(-3),
|
||||
LENGTH_LIMIT_EXCEEDED(-4),
|
||||
USER_NOT_FOUND(-11),
|
||||
TICKET_NOT_FOUND(-12),
|
||||
OPERATOR_NOT_FOUND(-13),
|
||||
UNAUTHORIZED(-20),
|
||||
WRONG_PASSWORD(-22),
|
||||
PERMISSION_DENIED(-24),
|
||||
INTERNAL_ERROR(-90),
|
||||
DATABASE_ERROR(-91),
|
||||
;
|
||||
|
||||
private static final Map<Integer, ResponseCode> ID_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (ResponseCode type : values()) {
|
||||
ID_MAP.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public final int id;
|
||||
|
||||
ResponseCode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static ResponseCode fromId(int id) {
|
||||
return ID_MAP.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +1,14 @@
|
||||
package love.sola.netsupport.api.manager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -28,62 +16,37 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "GetUser",urlPatterns = "/api/admin/getuser",loadOnStartup = 41)
|
||||
public class GetUser extends HttpServlet {
|
||||
public class GetUser extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
public GetUser() {
|
||||
url = "/admin/getuser";
|
||||
access = Access.LEADER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(query(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response query(HttpServletRequest request) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
if (op.getAccess() > Access.LEADER) {
|
||||
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
String id = request.getParameter("id");
|
||||
String name = request.getParameter("name");
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String id = req.getParameter("id");
|
||||
String name = req.getParameter("name");
|
||||
if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
|
||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
return Error.PARAMETER_REQUIRED;
|
||||
}
|
||||
if (id != null) {
|
||||
try {
|
||||
User u = TableUser.getById(Long.parseLong(id));
|
||||
if (u == null)
|
||||
return new Response(Response.ResponseCode.USER_NOT_FOUND);
|
||||
return Error.USER_NOT_FOUND;
|
||||
else
|
||||
return new Response(Response.ResponseCode.OK, u);
|
||||
return u;
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
return Error.ILLEGAL_PARAMETER;
|
||||
}
|
||||
} else {
|
||||
User u = TableUser.getByName(name);
|
||||
if (u == null)
|
||||
return new Response(Response.ResponseCode.USER_NOT_FOUND);
|
||||
return Error.USER_NOT_FOUND;
|
||||
else
|
||||
return new Response(Response.ResponseCode.OK, u);
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package love.sola.netsupport.api.manager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
@@ -9,21 +9,13 @@ import love.sola.netsupport.enums.Status;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -31,62 +23,35 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketPush",urlPatterns = "/api/admin/ticketpush",loadOnStartup = 42)
|
||||
public class TicketPush extends HttpServlet{
|
||||
public class TicketPush extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketPush() {
|
||||
url = "/admin/ticketpush";
|
||||
access = Access.LEADER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(push(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response push(HttpServletRequest request) {
|
||||
String uid = request.getParameter("uid");
|
||||
String desc = request.getParameter("desc");
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String uid = req.getParameter("uid");
|
||||
String desc = req.getParameter("desc");
|
||||
if (Checker.hasNull(uid, desc)) {
|
||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
return Error.PARAMETER_REQUIRED;
|
||||
}
|
||||
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||
return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED);
|
||||
return Error.LENGTH_LIMIT_EXCEEDED;
|
||||
}
|
||||
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
if (op.getAccess() > Access.LEADER) {
|
||||
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
s.beginTransaction();
|
||||
User u = s.get(User.class, Long.parseLong(uid));
|
||||
if (u == null) {
|
||||
return new Response(Response.ResponseCode.USER_NOT_FOUND);
|
||||
return Error.USER_NOT_FOUND;
|
||||
}
|
||||
Ticket t = new Ticket(null, u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
|
||||
s.save(t);
|
||||
s.getTransaction().commit();
|
||||
return new Response(Response.ResponseCode.OK, t);
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
package love.sola.netsupport.api.root;
|
||||
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.session.InternalSession;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -24,46 +15,25 @@ import java.util.Enumeration;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class DashBoard extends API {
|
||||
|
||||
@WebServlet(name = "Dashboard", urlPatterns = "/api/root/dashboard", loadOnStartup = 51)
|
||||
public class DashBoard extends HttpServlet {
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public DashBoard() {
|
||||
url = "/root/dashboard";
|
||||
access = Access.ROOT;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
process(request, out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void process(HttpServletRequest request, PrintWriter out) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
if (op.getAccess() != Access.ROOT) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
for (InternalSession s : WechatSession.list()) {
|
||||
out.println("=====" + s.getIdInternal() + "=====");
|
||||
WxSession ws = s.getSession();
|
||||
Enumeration<String> e = ws.getAttributeNames();
|
||||
while (e.hasMoreElements()) {
|
||||
String key = e.nextElement();
|
||||
out.println(key + ": " + ws.getAttribute(key));
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (love.sola.netsupport.session.WxSession ws : WechatSession.list()) {
|
||||
sb.append("=====").append(ws.getId()).append("=====\n");
|
||||
Set<String> e = ws.getAttributeNames();
|
||||
for (String key : e) {
|
||||
sb.append(key).append(": ").append(ws.getAttribute(key).toString()).append("\n");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
package love.sola.netsupport.api.root;
|
||||
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -22,38 +15,18 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class FlushCache extends API {
|
||||
|
||||
@WebServlet(name = "FlushCache", urlPatterns = "/api/root/flushcache", loadOnStartup = 52)
|
||||
public class FlushCache extends HttpServlet {
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public FlushCache() {
|
||||
url = "/root/flushcache";
|
||||
access = Access.ROOT;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
process(request, out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void process(HttpServletRequest request, PrintWriter out) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
if (op.getAccess() != Access.ROOT) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
TableUser.flushCache();
|
||||
out.println("Flushed wechat cache");
|
||||
return Error.OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
package love.sola.netsupport.api.root;
|
||||
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.Crypto;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -24,56 +18,31 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "SetPassword",urlPatterns = "/api/root/setpass",loadOnStartup = 53)
|
||||
public class SetPassword extends HttpServlet{
|
||||
public class SetPassword extends API {
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public SetPassword() {
|
||||
url = "/root/setpass";
|
||||
access = Access.ROOT;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
process(request, out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
private void process(HttpServletRequest request, PrintWriter out) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
if (op.getAccess() != Access.ROOT) {
|
||||
out.println("Unauthorized");
|
||||
return;
|
||||
}
|
||||
|
||||
String id = request.getParameter("id");
|
||||
String pass = request.getParameter("pass");
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String id = req.getParameter("id");
|
||||
String pass = req.getParameter("pass");
|
||||
if (pass == null || pass.length() < 8) {
|
||||
out.println("Invalid pass");
|
||||
return;
|
||||
return Error.INVALID_PARAMETER;
|
||||
}
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
s.beginTransaction();
|
||||
op = s.get(Operator.class, Integer.parseInt(id));
|
||||
Operator op = s.get(Operator.class, Integer.parseInt(id));
|
||||
if (op == null) {
|
||||
out.println("Invalid user");
|
||||
return;
|
||||
return Error.OPERATOR_NOT_FOUND;
|
||||
}
|
||||
op.setPassword(Crypto.hash(pass));
|
||||
s.update(op);
|
||||
s.getTransaction().commit();
|
||||
out.println("Operation success");
|
||||
} catch (NumberFormatException e) {
|
||||
out.println("Invalid id");
|
||||
return;
|
||||
return Error.OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,18 @@
|
||||
package love.sola.netsupport.api.stuff;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.envers.AuditReader;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -33,61 +23,36 @@ import java.util.Date;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketLog", urlPatterns = "/api/admin/ticketlog", loadOnStartup = 35)
|
||||
public class TicketLog extends HttpServlet {
|
||||
public class TicketLog extends API {
|
||||
|
||||
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketLog() {
|
||||
url = "/admin/ticketlog";
|
||||
access = Access.MEMBER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(query(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response query(HttpServletRequest request) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
int first;
|
||||
int limit;
|
||||
Date start;
|
||||
Date end;
|
||||
try {
|
||||
first = request.getParameter("first") == null ? 0 : Integer.parseInt(request.getParameter("first"));
|
||||
limit = request.getParameter("limit") == null ? 20 : Integer.parseInt(request.getParameter("limit"));
|
||||
start = request.getParameter("start") == null ? getToday() : dateFormat.parse(request.getParameter("start"));
|
||||
end = request.getParameter("end") == null ? getToday() : dateFormat.parse(request.getParameter("end"));
|
||||
end = DateUtils.addDays(end, 1);
|
||||
} catch (ParseException | NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
}
|
||||
first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
|
||||
limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
|
||||
start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
|
||||
end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
|
||||
end = DateUtils.addDays(end, 1);
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
AuditReader reader = TableTicket.getAuditReader(s);
|
||||
Object obj = reader.createQuery()
|
||||
return reader.createQuery()
|
||||
.forRevisionsOfEntity(Ticket.class, false, true)
|
||||
.addOrder(AuditEntity.revisionNumber().desc())
|
||||
.add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
|
||||
.setFirstResult(first)
|
||||
.setMaxResults(limit)
|
||||
.getResultList();
|
||||
return new Response(Response.ResponseCode.OK, obj);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,14 @@
|
||||
package love.sola.netsupport.api.stuff;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -29,52 +16,24 @@ import java.util.List;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketLookup", urlPatterns = "/api/admin/ticketlookup", loadOnStartup = 33)
|
||||
public class TicketLookup extends HttpServlet {
|
||||
public class TicketLookup extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketLookup() {
|
||||
url = "/admin/ticketlookup";
|
||||
access = Access.MEMBER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(lookup(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response lookup(HttpServletRequest request) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
try {
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
int block;
|
||||
if (request.getParameter("block") != null) {
|
||||
block = Integer.parseInt(request.getParameter("block"));
|
||||
} else {
|
||||
block = op.getBlock();
|
||||
}
|
||||
if (block == 0 && op.getAccess() > Access.MEMBER) {
|
||||
return new Response(Response.ResponseCode.PERMISSION_DENIED);
|
||||
}
|
||||
List<Ticket> list = TableTicket.unsolvedByBlock(block);
|
||||
return new Response(Response.ResponseCode.OK, list);
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||
int block;
|
||||
if (req.getParameter("block") != null) {
|
||||
block = Integer.parseInt(req.getParameter("block"));
|
||||
} else {
|
||||
block = op.getBlock();
|
||||
}
|
||||
return TableTicket.unsolvedByBlock(block);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
package love.sola.netsupport.api.stuff;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -24,47 +15,21 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TicketTrack extends API {
|
||||
|
||||
@WebServlet(name = "TicketTrack", urlPatterns = "/api/admin/tickettrack", loadOnStartup = 34)
|
||||
public class TicketTrack extends HttpServlet{
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketTrack() {
|
||||
url = "/admin/tickettrack";
|
||||
access = Access.MEMBER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(track(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response track(HttpServletRequest request) {
|
||||
String tid = request.getParameter("id");
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String tid = req.getParameter("id");
|
||||
if (tid == null) {
|
||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
}
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
try {
|
||||
return new Response(Response.ResponseCode.OK, TableTicket.track(Integer.parseInt(tid)));
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return Error.PARAMETER_REQUIRED;
|
||||
}
|
||||
return TableTicket.track(Integer.parseInt(tid));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
package love.sola.netsupport.api.stuff;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -28,39 +21,25 @@ import java.util.Date;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketUpdate", urlPatterns = "/api/admin/ticketupdate", loadOnStartup = 32)
|
||||
public class TicketUpdate extends HttpServlet {
|
||||
public class TicketUpdate extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketUpdate() {
|
||||
url = "/admin/ticketupdate";
|
||||
access = Access.MEMBER;
|
||||
authorize = Command.LOGIN;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(update(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response update(HttpServletRequest request) {
|
||||
String ticket = request.getParameter("ticket");
|
||||
String remark = request.getParameter("remark");
|
||||
String status = request.getParameter("status");
|
||||
if (Checker.hasNull(ticket, remark, status)) return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
WxSession session = Checker.isAuthorized(request, Command.LOGIN);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String ticket = req.getParameter("ticket");
|
||||
String remark = req.getParameter("remark");
|
||||
String status = req.getParameter("status");
|
||||
if (Checker.hasNull(ticket, remark, status)) return Error.PARAMETER_REQUIRED;
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
Operator op = (Operator) session.getAttribute(Attribute.OPERATOR);
|
||||
Operator op = session.getAttribute(Attribute.OPERATOR);
|
||||
Ticket t = s.get(Ticket.class, Integer.parseInt(ticket));
|
||||
if (t == null) {
|
||||
return new Response(Response.ResponseCode.TICKET_NOT_FOUND);
|
||||
return Error.TICKET_NOT_FOUND;
|
||||
}
|
||||
t.setOperator(op);
|
||||
t.setRemark(remark);
|
||||
@@ -69,16 +48,7 @@ public class TicketUpdate extends HttpServlet {
|
||||
s.beginTransaction();
|
||||
s.update(t);
|
||||
s.getTransaction().commit();
|
||||
return new Response(Response.ResponseCode.OK, t);
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
package love.sola.netsupport.api.user;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import static love.sola.netsupport.util.Checker.*;
|
||||
|
||||
@@ -29,44 +21,28 @@ import static love.sola.netsupport.util.Checker.*;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "ProfileModify", urlPatterns = "/api/profilemodify", loadOnStartup = 22)
|
||||
public class ProfileModify extends HttpServlet {
|
||||
public class ProfileModify extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public ProfileModify() {
|
||||
url = "/profilemodify";
|
||||
access = Access.USER;
|
||||
authorize = Command.PROFILE;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(process(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response process(HttpServletRequest request) {
|
||||
WxSession session = Checker.isAuthorized(request, Command.PROFILE);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
User u = (User) session.getAttribute(Attribute.USER);
|
||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
|
||||
ISP isp = checkISP(request.getParameter("isp"));
|
||||
String netAccount = checkNetAccount(request.getParameter("username"), isp);
|
||||
int block = checkBlock(request.getParameter("block"));
|
||||
int room = checkRoom(request.getParameter("room"), block);
|
||||
long phone = checkPhoneNumber(request.getParameter("phone"));
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
User u = session.getAttribute(Attribute.USER);
|
||||
ISP isp = checkISP(req.getParameter("isp"));
|
||||
String netAccount = checkNetAccount(req.getParameter("username"), isp);
|
||||
int block = checkBlock(req.getParameter("block"));
|
||||
int room = checkRoom(req.getParameter("room"), block);
|
||||
long phone = checkPhoneNumber(req.getParameter("phone"));
|
||||
if (room == -1)
|
||||
return new Response(Response.ResponseCode.REQUEST_FAILED, "Invalid_Room");
|
||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
||||
if (phone == -1)
|
||||
return new Response(Response.ResponseCode.REQUEST_FAILED, "Invalid_Phone_Number");
|
||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
||||
if (netAccount == null)
|
||||
return new Response(Response.ResponseCode.REQUEST_FAILED, "Invalid_Account");
|
||||
return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
||||
|
||||
u.setIsp(isp);
|
||||
u.setNetAccount(netAccount);
|
||||
@@ -77,12 +53,9 @@ public class ProfileModify extends HttpServlet {
|
||||
TableUser.update(u);
|
||||
} catch (ConstraintViolationException e) {
|
||||
String dupKey = e.getConstraintName();
|
||||
return new Response(Response.ResponseCode.REQUEST_FAILED, "Duplicated_" + dupKey.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase());
|
||||
}
|
||||
session.invalidate();
|
||||
return new Response(Response.ResponseCode.OK);
|
||||
return Error.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
package love.sola.netsupport.api.user;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WxMpServlet;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -36,66 +29,45 @@ import static love.sola.netsupport.util.Checker.*;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "Register", urlPatterns = "/api/register", loadOnStartup = 21)
|
||||
public class Register extends HttpServlet {
|
||||
public class Register extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
public Register() {
|
||||
url = "/register";
|
||||
access = Access.GUEST;
|
||||
authorize = Command.REGISTER;
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
|
||||
WxSession session = Checker.isAuthorized(request, Command.REGISTER);
|
||||
if (session == null) {
|
||||
printAuthorizeFailed(request, out);
|
||||
return;
|
||||
}
|
||||
String wechat = (String) session.getAttribute(Attribute.WECHAT);
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String wechat = session.getAttribute(Attribute.WECHAT);
|
||||
if (wechat == null) {
|
||||
printAuthorizeFailed(request, out);
|
||||
return;
|
||||
return Error.UNAUTHORIZED;
|
||||
}
|
||||
|
||||
ISP isp = checkISP(request.getParameter("isp"));
|
||||
int block = checkBlock(request.getParameter("block"));
|
||||
String result = register(
|
||||
checkStudentId(request.getParameter("sid")),
|
||||
request.getParameter("name"),
|
||||
ISP isp = checkISP(req.getParameter("isp"));
|
||||
int block = checkBlock(req.getParameter("block"));
|
||||
return register(
|
||||
checkStudentId(req.getParameter("sid")),
|
||||
req.getParameter("name"),
|
||||
isp,
|
||||
checkNetAccount(request.getParameter("username"), isp),
|
||||
checkNetAccount(req.getParameter("username"), isp),
|
||||
block,
|
||||
checkRoom(request.getParameter("room"), block),
|
||||
checkPhoneNumber(request.getParameter("phone")),
|
||||
wechat
|
||||
);
|
||||
boolean isSuccess = result.equals("Register_Success");
|
||||
if (isSuccess) {
|
||||
session.invalidate();
|
||||
out.println(ParseUtil.parseJsonP(request, gson.toJson(new Response(Response.ResponseCode.OK, result))));
|
||||
} else {
|
||||
out.println(ParseUtil.parseJsonP(request, gson.toJson(new Response(Response.ResponseCode.REQUEST_FAILED, result))));
|
||||
}
|
||||
out.close();
|
||||
checkRoom(req.getParameter("room"), block),
|
||||
checkPhoneNumber(req.getParameter("phone")),
|
||||
wechat);
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doPost(request, response);
|
||||
}
|
||||
|
||||
private String register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
|
||||
if (sid == -1) return "Invalid_Student_Id";
|
||||
if (name == null) return "Invalid_Name";
|
||||
if (isp == null) return "Invalid_ISP";
|
||||
if (netAccount == null) return "Invalid_Account";
|
||||
if (block == -1) return "Invalid_Block";
|
||||
if (room == -1) return "Invalid_Room";
|
||||
if (phone == -1) return "Invalid_Phone_Number";
|
||||
private Object register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
|
||||
if (sid == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
||||
if (name == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
||||
if (isp == null) return Error.INVALID_PARAMETER.withMsg("Invalid_ISP");
|
||||
if (netAccount == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
|
||||
if (block == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Block");
|
||||
if (room == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
|
||||
if (phone == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
|
||||
User user = TableUser.getById(sid);
|
||||
if (user == null) return "Invalid_Student_Id";
|
||||
if (!user.getName().equals(name)) return "Invalid_Name";
|
||||
if (user.getWechatId() != null) return "User_Already_Registered";
|
||||
if (user == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
|
||||
if (!user.getName().equals(name)) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
|
||||
if (user.getWechatId() != null) return Error.INVALID_PARAMETER.withMsg("User_Already_Registered");
|
||||
user.setIsp(isp);
|
||||
user.setNetAccount(netAccount);
|
||||
user.setBlock(block);
|
||||
@@ -106,17 +78,11 @@ public class Register extends HttpServlet {
|
||||
TableUser.update(user);
|
||||
} catch (ConstraintViolationException e) {
|
||||
String dupKey = e.getConstraintName();
|
||||
return "Duplicated_" + dupKey.toUpperCase(); // PHONE ACCOUNT WECHAT
|
||||
return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase()); // PHONE ACCOUNT WECHAT
|
||||
}
|
||||
// FIXME: 2015/12/30 Temporary converter
|
||||
converterWithRetry(user);
|
||||
return "Register_Success";
|
||||
}
|
||||
|
||||
private void printAuthorizeFailed(HttpServletRequest request, PrintWriter out) {
|
||||
out.println(ParseUtil.parseJsonP(request, gson.toJson(new Response(Response.ResponseCode.UNAUTHORIZED))));
|
||||
out.close();
|
||||
return;
|
||||
return Error.OK;
|
||||
}
|
||||
|
||||
public static void converterWithRetry(User u) {
|
||||
@@ -155,8 +121,6 @@ public class Register extends HttpServlet {
|
||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("已进行过数据转换").build());
|
||||
}
|
||||
}
|
||||
} catch (SQLException | WxErrorException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
package love.sola.netsupport.api.user;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -30,60 +21,34 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketQuery", urlPatterns = "/api/ticketquery", loadOnStartup = 24)
|
||||
public class TicketQuery extends HttpServlet {
|
||||
public class TicketQuery extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(query(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
public TicketQuery() {
|
||||
url = "/ticketquery";
|
||||
access = Access.USER;
|
||||
authorize = Command.QUERY;
|
||||
}
|
||||
|
||||
private Response query(HttpServletRequest request) {
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
|
||||
WxSession session = Checker.isAuthorized(request, Command.QUERY);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
User u = (User) session.getAttribute(Attribute.USER);
|
||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
|
||||
User u = session.getAttribute(Attribute.USER);
|
||||
Criteria c = s.createCriteria(Ticket.class);
|
||||
int first = request.getParameter("offset") == null ? 0 : Integer.parseInt(request.getParameter("offset"));
|
||||
int limit = request.getParameter("limit") == null ? 5 : Integer.parseInt(request.getParameter("limit"));
|
||||
int first = req.getParameter("offset") == null ? 0 : Integer.parseInt(req.getParameter("offset"));
|
||||
int limit = req.getParameter("limit") == null ? 5 : Integer.parseInt(req.getParameter("limit"));
|
||||
c.setFirstResult(first);
|
||||
c.setMaxResults(limit);
|
||||
c.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME));
|
||||
c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
|
||||
if (request.getParameter("status") != null) {
|
||||
c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(request.getParameter("status"))));
|
||||
} else if (request.getParameter("statusl") != null && request.getParameter("statush") != null) {
|
||||
if (req.getParameter("status") != null) {
|
||||
c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(req.getParameter("status"))));
|
||||
} else if (req.getParameter("statusl") != null && req.getParameter("statush") != null) {
|
||||
c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
|
||||
Integer.parseInt(request.getParameter("statusl")),
|
||||
Integer.parseInt(request.getParameter("statush"))
|
||||
Integer.parseInt(req.getParameter("statusl")),
|
||||
Integer.parseInt(req.getParameter("statush"))
|
||||
));
|
||||
}
|
||||
return new Response(Response.ResponseCode.OK, c.list());
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return c.list();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
package love.sola.netsupport.api.user;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.api.API;
|
||||
import love.sola.netsupport.api.Error;
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -29,48 +21,30 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketSubmit", urlPatterns = "/api/ticketsubmit", loadOnStartup = 23)
|
||||
public class TicketSubmit extends HttpServlet {
|
||||
public class TicketSubmit extends API {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doGet(request, response);
|
||||
public TicketSubmit() {
|
||||
url = "/ticketsubmit";
|
||||
access = Access.USER;
|
||||
authorize = Command.SUBMIT;
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "application/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(submit(request));
|
||||
out.println(ParseUtil.parseJsonP(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
private Response submit(HttpServletRequest request) {
|
||||
String desc = request.getParameter("desc");
|
||||
@Override
|
||||
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
|
||||
String desc = req.getParameter("desc");
|
||||
if (desc == null || desc.isEmpty()) {
|
||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
return Error.PARAMETER_REQUIRED;
|
||||
}
|
||||
if (desc.length() > Settings.MAX_DESC_LENGTH) {
|
||||
return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED);
|
||||
return Error.LENGTH_LIMIT_EXCEEDED;
|
||||
}
|
||||
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
|
||||
WxSession session = Checker.isAuthorized(request, Command.SUBMIT);
|
||||
if (session == null) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
User u = (User) session.getAttribute(Attribute.USER);
|
||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
|
||||
User u = session.getAttribute(Attribute.USER);
|
||||
if (TableTicket.hasOpen(u)) {
|
||||
session.invalidate();
|
||||
return new Response(Response.ResponseCode.ALREADY_SUBMITTED);
|
||||
return Error.ALREADY_SUBMITTED;
|
||||
}
|
||||
|
||||
Ticket t = new Ticket();
|
||||
t.setUser(u);
|
||||
t.setDescription(desc);
|
||||
@@ -79,17 +53,7 @@ public class TicketSubmit extends HttpServlet {
|
||||
s.save(t);
|
||||
s.getTransaction().commit();
|
||||
session.invalidate();
|
||||
return new Response(Response.ResponseCode.OK, t);
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage());
|
||||
return Error.OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
69
src/main/java/love/sola/netsupport/auth/OAuth2.java
Normal file
69
src/main/java/love/sola/netsupport/auth/OAuth2.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package love.sola.netsupport.auth;
|
||||
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
import love.sola.netsupport.wechat.WxMpServlet;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2014/8/20.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "OAuth2", urlPatterns = "/oauth2/callback", loadOnStartup = 21, asyncSupported = true)
|
||||
public class OAuth2 extends HttpServlet {
|
||||
|
||||
private static Map<String, OAuth2Handler> oAuth2HandlerMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* for {@link love.sola.netsupport.wechat.WxMpServlet#registerCommands}
|
||||
* @param state the state key from open platform callback.
|
||||
* @param handler handler
|
||||
*/
|
||||
public static void registerOAuth2Handler(String state, OAuth2Handler handler) {
|
||||
oAuth2HandlerMap.put(state, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
AsyncContext actx = req.startAsync();
|
||||
String code = req.getParameter("code");
|
||||
String state = req.getParameter("state");
|
||||
if (Checker.hasNull(code, state)) {
|
||||
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
OAuth2Handler handler = oAuth2HandlerMap.get(state);
|
||||
if (handler == null) {
|
||||
resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
|
||||
return;
|
||||
}
|
||||
actx.start(() -> {
|
||||
try {
|
||||
WxMpService wxMpService = WxMpServlet.instance.wxMpService;
|
||||
WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
|
||||
String wechat = token.getOpenId();
|
||||
WxSession session = WechatSession.create();
|
||||
handler.onOAuth2(actx, (HttpServletResponse) actx.getResponse(), wechat, session);
|
||||
actx.complete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
18
src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
Normal file
18
src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package love.sola.netsupport.auth;
|
||||
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2016/3/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public interface OAuth2Handler {
|
||||
|
||||
void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session);
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import static love.sola.netsupport.config.Lang.lang;
|
||||
*/
|
||||
public class Access {
|
||||
|
||||
public static final int GOD_MODE = -1;
|
||||
public static final int ROOT = 0;
|
||||
public static final int MANAGER = 1;
|
||||
public static final int CO_MANAGER = 2;
|
||||
@@ -23,7 +24,9 @@ public class Access {
|
||||
public static final int ELDER = 6;
|
||||
public static final int MEMBER = 7;
|
||||
public static final int PRE_MEMBER = 8;
|
||||
public static final int NOLOGIN = 9;
|
||||
public static final int NO_LOGIN = 9;
|
||||
public static final int USER = 10;
|
||||
public static final int GUEST = 11;
|
||||
|
||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||
|
||||
|
||||
88
src/main/java/love/sola/netsupport/session/MapSession.java
Normal file
88
src/main/java/love/sola/netsupport/session/MapSession.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package love.sola.netsupport.session;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Sola
|
||||
*/
|
||||
@EqualsAndHashCode(of = "id")
|
||||
public final class MapSession implements WxSession, Serializable {
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
|
||||
@Getter
|
||||
private long creationTime = System.currentTimeMillis();
|
||||
@Getter
|
||||
@Setter
|
||||
private long lastAccessedTime = creationTime;
|
||||
@Getter
|
||||
private boolean invalidated = false;
|
||||
|
||||
/**
|
||||
* Creates a new instance with a secure randomly generated identifier.
|
||||
*/
|
||||
public MapSession() {
|
||||
this(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance with the specified id. This is preferred to the
|
||||
* default constructor when the id is known to prevent unnecessary consumption on
|
||||
* entropy which can be slow.
|
||||
*
|
||||
* @param id the identifier to use
|
||||
*/
|
||||
public MapSession(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAttribute(String attributeName) {
|
||||
return (T) sessionAttrs.get(attributeName);
|
||||
}
|
||||
|
||||
public Set<String> getAttributeNames() {
|
||||
return sessionAttrs.keySet();
|
||||
}
|
||||
|
||||
public void setAttribute(String attributeName, Object attributeValue) {
|
||||
if (attributeValue == null) {
|
||||
removeAttribute(attributeName);
|
||||
} else {
|
||||
sessionAttrs.put(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAttribute(String attributeName) {
|
||||
sessionAttrs.remove(attributeName);
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
invalidated = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package love.sola.netsupport.session;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Sola
|
||||
*/
|
||||
public class MapSessionRepository {
|
||||
|
||||
private final LoadingCache<String, MapSession> sessions;
|
||||
|
||||
public MapSessionRepository() {
|
||||
this(CacheBuilder.newBuilder()
|
||||
.concurrencyLevel(4)
|
||||
.maximumSize(65535)
|
||||
.expireAfterAccess(Settings.I.User_Session_Max_Inactive, TimeUnit.SECONDS)
|
||||
.build(new CacheLoader<String, MapSession>() {
|
||||
@Override
|
||||
public MapSession load(@Nonnull String key) throws Exception {
|
||||
return new MapSession(key);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public MapSessionRepository(LoadingCache<String, MapSession> sessions) {
|
||||
Validate.notNull(sessions);
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
||||
public void save(MapSession session) {
|
||||
sessions.put(session.getId(), session);
|
||||
}
|
||||
|
||||
public MapSession getSession(String id) {
|
||||
MapSession saved = sessions.getIfPresent(id);
|
||||
if (saved == null) {
|
||||
return null;
|
||||
}
|
||||
if (saved.isInvalidated()) {
|
||||
delete(saved.getId());
|
||||
return null;
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
sessions.invalidate(id);
|
||||
}
|
||||
|
||||
public MapSession createSession() {
|
||||
MapSession session = new MapSession();
|
||||
save(session);
|
||||
return session;
|
||||
}
|
||||
|
||||
public Map<String, MapSession> asMap() {
|
||||
return sessions.asMap();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package love.sola.netsupport.session;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/14.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class WechatSession {
|
||||
|
||||
private static MapSessionRepository repository;
|
||||
|
||||
static {
|
||||
repository = new MapSessionRepository();
|
||||
}
|
||||
|
||||
public static WxSession get(String id) {
|
||||
return repository.getSession(id);
|
||||
}
|
||||
|
||||
public static WxSession create() {
|
||||
return repository.createSession();
|
||||
}
|
||||
|
||||
public static Collection<? extends WxSession> list() {
|
||||
return repository.asMap().values();
|
||||
}
|
||||
|
||||
}
|
||||
22
src/main/java/love/sola/netsupport/session/WxSession.java
Normal file
22
src/main/java/love/sola/netsupport/session/WxSession.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package love.sola.netsupport.session;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Sola
|
||||
*/
|
||||
public interface WxSession {
|
||||
|
||||
String getId();
|
||||
|
||||
<T> T getAttribute(String name);
|
||||
|
||||
Set<String> getAttributeNames();
|
||||
|
||||
void setAttribute(String name, Object value);
|
||||
|
||||
void removeAttribute(String name);
|
||||
|
||||
void invalidate();
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import org.hibernate.Hibernate;
|
||||
@@ -18,6 +19,7 @@ import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
@@ -30,7 +32,10 @@ import java.util.Date;
|
||||
*/
|
||||
public class SQLCore {
|
||||
|
||||
public static InitialContext ic;
|
||||
public static DataSource ds;
|
||||
public static SessionFactory sf;
|
||||
public static ServiceRegistry sr;
|
||||
public static Gson gson = new GsonBuilder()
|
||||
.addSerializationExclusionStrategy(new ExclusionStrategy() {
|
||||
@Override
|
||||
@@ -64,12 +69,10 @@ public class SQLCore {
|
||||
.registerTypeAdapter(Command.class, (JsonSerializer<Command>) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
|
||||
.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
|
||||
.create();
|
||||
public static SessionFactory sf;
|
||||
public static ServiceRegistry sr;
|
||||
|
||||
static {
|
||||
try {
|
||||
InitialContext ic = new InitialContext();
|
||||
ic = new InitialContext();
|
||||
ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
|
||||
ds.setLoginTimeout(3);
|
||||
|
||||
@@ -83,6 +86,16 @@ public class SQLCore {
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
try {
|
||||
SQLCore.sf.close();
|
||||
((ComboPooledDataSource) SQLCore.ds).close();
|
||||
SQLCore.ic.close();
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static AuditReader getAuditReader(Session session) {
|
||||
return AuditReaderFactory.get(session);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class TableUser extends SQLCore {
|
||||
private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
|
||||
.concurrencyLevel(4)
|
||||
.maximumSize(4096)
|
||||
.expireAfterWrite(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||
.expireAfterAccess(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
|
||||
.build(new ValueLoader());
|
||||
|
||||
private static class ValueLoader extends CacheLoader<String, User> {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.enums.Block;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -25,13 +19,6 @@ public class Checker {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static WxSession isAuthorized(HttpServletRequest r, Command c) {
|
||||
String t = r.getParameter("token");
|
||||
if (t == null || t.isEmpty()) return null;
|
||||
WxSession s = WechatSession.get(t, false);
|
||||
return s == null ? null : s.getAttribute(Attribute.AUTHORIZED) == c ? s : null;
|
||||
}
|
||||
|
||||
public static long checkStudentId(String studentId) {
|
||||
if (studentId == null) return -1;
|
||||
if (studentId.matches(STUDENT_ID_REGEX)) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package love.sola.netsupport.util;
|
||||
import love.sola.netsupport.enums.Status;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
@@ -30,11 +29,4 @@ public class ParseUtil {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String parseJsonP(HttpServletRequest request, String json) {
|
||||
String jsonp = request.getParameter("jsonp");
|
||||
if (jsonp == null || jsonp.isEmpty())
|
||||
return json;
|
||||
else
|
||||
return jsonp.replace("{0}", json);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import com.google.common.net.UrlEscapers;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -13,15 +15,106 @@ import static love.sola.netsupport.config.Lang.lang;
|
||||
*/
|
||||
public class Redirect {
|
||||
|
||||
public static final String REDIRECT_PAGE = lang("Result_Page");
|
||||
private static final String REDIRECT_PAGE = lang("Result_Page");
|
||||
|
||||
private static final int SUCCESS = 1;
|
||||
private static final int ERROR = 0;
|
||||
private static final int WARNING = -1;
|
||||
private static final int NON_WECHAT = 88;
|
||||
|
||||
public static RedirectBuilder success() {
|
||||
return new RedirectBuilder(SUCCESS);
|
||||
}
|
||||
|
||||
public static RedirectBuilder error() {
|
||||
return new RedirectBuilder(ERROR);
|
||||
}
|
||||
|
||||
public static class RedirectBuilder {
|
||||
|
||||
private StringBuilder sb;
|
||||
|
||||
RedirectBuilder(int type) {
|
||||
sb = new StringBuilder(REDIRECT_PAGE).append("?");
|
||||
type(type);
|
||||
}
|
||||
|
||||
private RedirectBuilder type(int type) {
|
||||
sb.append("type=").append(type).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder msg(String msg) {
|
||||
sb.append("msg=").append(escape(msg)).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder title(String title) {
|
||||
sb.append("title=").append(escape(title)).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder noButton() {
|
||||
sb.append("btn=").append("hide").append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder button(String text) {
|
||||
sb.append("btn=").append(escape(text)).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder icon(WeUIIcon icon) {
|
||||
sb.append("icon=").append(icon.toString()).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public RedirectBuilder to(String url) {
|
||||
sb.append("redirect=").append(escape(url)).append("&");
|
||||
return this;
|
||||
}
|
||||
|
||||
public void go(HttpServletResponse resp) throws IOException {
|
||||
resp.sendRedirect(sb.toString());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String escape(String str) {
|
||||
return UrlEscapers.urlFragmentEscaper().escape(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum WeUIIcon {
|
||||
SUCCESS("weui_icon_success"),
|
||||
SUCCESS_CIRCLE("weui_icon_success_circle"),
|
||||
SUCCESS_NO_CIRCLE("weui_icon_success_no_circle"),
|
||||
SUCCESS_SAFE("weui_icon_safe_success"),
|
||||
INFO("weui_icon_info"),
|
||||
INFO_CIRCLE("weui_icon_info_circle"),
|
||||
WAITING("weui_icon_waiting"),
|
||||
WAITING_CIRCLE("weui_icon_waiting_circle"),
|
||||
CIRCLE("weui_icon_circle"),
|
||||
WARN("weui_icon_warn"),
|
||||
WARN_SAFE("weui_icon_safe_warn"),
|
||||
DOWNLOAD("weui_icon_download"),
|
||||
CANCEL("weui_icon_cancel"),
|
||||
;
|
||||
|
||||
private String value;
|
||||
|
||||
WeUIIcon(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void message(HttpServletResponse response, int type, String message) throws IOException {
|
||||
response.sendRedirect(
|
||||
response.encodeRedirectURL(REDIRECT_PAGE +
|
||||
"?msg=" + message +
|
||||
"&type=" + type
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import me.chanjar.weixin.common.session.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/14.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class WechatSession {
|
||||
|
||||
private static StandardSessionManager manager;
|
||||
|
||||
static{
|
||||
manager = new StandardSessionManager();
|
||||
manager.setMaxInactiveInterval(Settings.I.User_Session_Max_Inactive);
|
||||
}
|
||||
|
||||
public static WxSession get(String id, boolean create) {
|
||||
WxSession session = manager.getSession(id, create);
|
||||
if (session != null) {
|
||||
((StandardSessionFacade) session).getInternalSession().endAccess();
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
public static WxSession get(String id) {
|
||||
return get(id, true);
|
||||
}
|
||||
|
||||
public static String genId() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public static InternalSession[] list() {
|
||||
return manager.findSessions();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import love.sola.netsupport.auth.OAuth2;
|
||||
import love.sola.netsupport.auth.OAuth2Handler;
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
||||
import love.sola.netsupport.wechat.handler.SubscribeHandler;
|
||||
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
||||
@@ -86,6 +89,9 @@ public class WxMpServlet extends HttpServlet {
|
||||
WxMpMessageHandler handler = c.handler.newInstance();
|
||||
router.rule().async(false).msgType(WxConsts.XML_MSG_TEXT).rContent(c.regex).handler(handler).end();
|
||||
router.rule().async(false).msgType(WxConsts.XML_MSG_EVENT).event(WxConsts.EVT_CLICK).eventKey(c.name()).handler(handler).end();
|
||||
if (handler instanceof OAuth2Handler) {
|
||||
OAuth2.registerOAuth2Handler(c.name(), (OAuth2Handler) handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,4 +159,8 @@ public class WxMpServlet extends HttpServlet {
|
||||
doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
SQLCore.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package love.sola.netsupport.wechat.handler;
|
||||
|
||||
import love.sola.netsupport.auth.OAuth2Handler;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Redirect;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -14,9 +16,12 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.format;
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -24,19 +29,39 @@ import static love.sola.netsupport.config.Lang.format;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class ProfileHandler implements WxMpMessageHandler {
|
||||
public class ProfileHandler implements WxMpMessageHandler, OAuth2Handler {
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||
User u = TableUser.getByWechat(wxMessage.getFromUserName());
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||
out.content(format("Profile_Modify", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||
out.content(format("Profile_Modify", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session) {
|
||||
try {
|
||||
User u = TableUser.getByWechat(user);
|
||||
if (u == null) {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||
session.setAttribute(Attribute.WECHAT, user);
|
||||
Redirect.error().icon(Redirect.WeUIIcon.INFO).noButton()
|
||||
.title(lang("Need_Register_Title")).msg(lang("Need_Register"))
|
||||
.to(format("User_Register_Link", session.getId())).go(resp);
|
||||
return;
|
||||
}
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||
session.setAttribute(Attribute.WECHAT, user);
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
resp.sendRedirect(format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ package love.sola.netsupport.wechat.handler;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.ParseUtil;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -40,8 +40,7 @@ public class QueryHandler implements WxMpMessageHandler {
|
||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.content(lang("No_Ticket_Available")).build();
|
||||
}
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.QUERY);
|
||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
@@ -50,7 +49,7 @@ public class QueryHandler implements WxMpMessageHandler {
|
||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||
item.setTitle(lang("Query_Title"));
|
||||
item.setDescription(ParseUtil.parseTicket(t) + "\n" + lang("More_Details"));
|
||||
item.setUrl(format("User_Query_Link", id));
|
||||
item.setUrl(format("User_Query_Link", session.getId()));
|
||||
out.addArticle(item);
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package love.sola.netsupport.wechat.handler;
|
||||
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -32,17 +32,16 @@ public class RegisterHandler implements WxMpMessageHandler {
|
||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||
String fromUser = wxMessage.getFromUserName();
|
||||
User u = TableUser.getByWechat(fromUser);
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
if (u != null) {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
out.content(format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||
out.content(format("Already_Registered", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone())));
|
||||
} else {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||
out.content(format("User_Register", format("User_Register_Link", id)));
|
||||
out.content(format("User_Register", format("User_Register_Link", session.getId())));
|
||||
}
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package love.sola.netsupport.wechat.handler;
|
||||
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -36,8 +36,7 @@ public class SubmitHandler implements WxMpMessageHandler {
|
||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.content(lang("Already_Opening_Ticket")).build();
|
||||
}
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.SUBMIT);
|
||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
@@ -46,7 +45,7 @@ public class SubmitHandler implements WxMpMessageHandler {
|
||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||
item.setTitle(lang("Submit_Title"));
|
||||
item.setDescription(lang("Submit_Desc"));
|
||||
item.setUrl(format("User_Submit_Link", id, u.getName(), u.getIsp().id, u.getRoom(), u.getBlock(), u.getPhone()));
|
||||
item.setUrl(format("User_Submit_Link", session.getId(), u.getName(), u.getIsp().id, u.getRoom(), u.getBlock(), u.getPhone()));
|
||||
out.addArticle(item);
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ import love.sola.netsupport.api.user.Register;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableOperator;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -34,13 +34,12 @@ public class SubscribeHandler implements WxMpMessageHandler {
|
||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||
String fromUser = wxMessage.getFromUserName();
|
||||
User u = TableUser.getByWechat(fromUser);
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
if (u != null) {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.PROFILE);
|
||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||
session.setAttribute(Attribute.USER, u);
|
||||
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
||||
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", session.getId(), u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
||||
|
||||
Operator op = TableOperator.get(fromUser);
|
||||
if (op != null) {
|
||||
@@ -51,7 +50,7 @@ public class SubscribeHandler implements WxMpMessageHandler {
|
||||
} else {
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||
out.content(format("Event_Subscribe", format("User_Register", format("User_Register_Link", id))));
|
||||
out.content(format("Event_Subscribe", format("User_Register", format("User_Register_Link", session.getId()))));
|
||||
}
|
||||
return out.build();
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package love.sola.netsupport.wechat.handler.admin;
|
||||
|
||||
import love.sola.netsupport.auth.OAuth2Handler;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.enums.Attribute;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.session.WechatSession;
|
||||
import love.sola.netsupport.session.WxSession;
|
||||
import love.sola.netsupport.sql.TableOperator;
|
||||
import love.sola.netsupport.util.Redirect;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import love.sola.netsupport.wechat.WechatSession;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSession;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
@@ -15,6 +17,8 @@ import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.TextBuilder;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.format;
|
||||
@@ -26,7 +30,7 @@ import static love.sola.netsupport.config.Lang.lang;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class LoginHandler implements WxMpMessageHandler {
|
||||
public class LoginHandler implements WxMpMessageHandler, OAuth2Handler {
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||
@@ -35,17 +39,15 @@ public class LoginHandler implements WxMpMessageHandler {
|
||||
Operator operator = TableOperator.get(wxMessage.getFromUserName());
|
||||
if (operator == null)
|
||||
out.content(lang("Not_Operator"));
|
||||
else if (operator.getAccess() == Access.NOLOGIN) {
|
||||
else if (operator.getAccess() >= Access.NO_LOGIN) {
|
||||
out.content(lang("No_Login"));
|
||||
} else {
|
||||
String id = WechatSession.genId();
|
||||
WxSession session = WechatSession.get(id, true);
|
||||
WxSession session = WechatSession.create();
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
||||
session.setAttribute(Attribute.WECHAT, wxMessage.getFromUserName());
|
||||
session.setAttribute(Attribute.OPERATOR, operator);
|
||||
out.content(format("Operator_Home_Page", id));
|
||||
out.content(format("Home_Page_Msg", format("Operator_Home_Page", session.getId())));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
out.content(lang("Login_Error"));
|
||||
@@ -53,4 +55,28 @@ public class LoginHandler implements WxMpMessageHandler {
|
||||
return out.build();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session) {
|
||||
try {
|
||||
Operator operator = TableOperator.get(user);
|
||||
if (operator == null) {
|
||||
Redirect.error().icon(Redirect.WeUIIcon.WARN_SAFE).noButton()
|
||||
.title(lang("Not_Operator")).msg(lang("Not_Operator_OAuth2")).go(resp);
|
||||
return;
|
||||
}
|
||||
if (operator.getAccess() >= Access.NO_LOGIN) {
|
||||
Redirect.error().icon(Redirect.WeUIIcon.WAITING).noButton()
|
||||
.title(lang("Left_Operator_Title")).msg(lang("Left_Operator")).go(resp);
|
||||
return;
|
||||
}
|
||||
session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
|
||||
session.setAttribute(Attribute.WECHAT, user);
|
||||
session.setAttribute(Attribute.OPERATOR, operator);
|
||||
resp.sendRedirect(format("Operator_Home_Page", session.getId()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package love.sola.netsupport.wechat.handler.admin;
|
||||
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.sql.TableOperator;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
@@ -29,10 +28,10 @@ public class OperatorInfoHandler implements WxMpMessageHandler {
|
||||
TextBuilder out = WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||
try {
|
||||
Operator op = TableOperator.get(wxMessage.getFromUserName());
|
||||
if (op == null)
|
||||
if (op == null) {
|
||||
out.content(lang("Not_Operator"));
|
||||
else if (op.getAccess() == Access.NOLOGIN) {
|
||||
out.content(lang("No_Login"));
|
||||
// } else if (op.getAccess() >= Access.NO_LOGIN) {
|
||||
// out.content(lang("No_Login"));
|
||||
} else {
|
||||
out.content(format("Operator_Info", op.getId(), op.getName(), op.getAccess(), op.getBlock(), op.getWeek()));
|
||||
}
|
||||
|
||||
@@ -42,28 +42,34 @@ User_Cancel_Remark: '用户手动取消报修。'
|
||||
Cancel_Failed: '取消失败。'
|
||||
#Modify
|
||||
Profile_Modify: '<a href="{0}">> 点此修改资料 <</a>'
|
||||
Need_Register_Title: '尚未进行微信绑定'
|
||||
Need_Register: '您尚未进行微信绑定,3秒后将自动跳转至微信绑定页面。'
|
||||
#Login
|
||||
Home_Page_Msg: '<a href="{0}">CLICK HERE</a>'
|
||||
Not_Operator: '嘟嘟嘟……'
|
||||
Not_Operator_OAuth2: '看起来你并不是我们网维大家族的一员,但我们随时都欢迎你的加入哦!'
|
||||
No_Login: 'Permission Denied.'
|
||||
Left_Operator_Title: '一路上有你'
|
||||
Left_Operator: '网络维护科的茁壮成长离不开每一位成员的陪伴。一路上有你,感谢你对网络维护科的贡献!'
|
||||
Internal_Error: '啊哦,登录失败了哦。'
|
||||
#Operator_Info
|
||||
Operator_Info: |
|
||||
网维成员资料:
|
||||
网维ID: {0,number,#}
|
||||
姓名: {1}
|
||||
岗位: {2,choice,0#'Administrator >ω<'|3#值班组长|6#正式成员|7#实习成员|}
|
||||
岗位: {2,choice,0#'Administrator >ω<'|3#值班组长|6#正式成员|7#实习成员|9#'曾经的一员(TдT)'}
|
||||
值班片区: {3,choice,0#'全图 >ω<'|1#岐头片区|2#北门片区|3#东门片区|4#香灰片区|5#凤翔片区}
|
||||
值班日: {4,choice,0#'2月30日 >ω<'|1#周一|2#周二|3#周三|4#周四|5#周五|6#周六|7#周日}
|
||||
|
||||
若以上信息有误,请及时联系@15-排污-沙子森。
|
||||
若以上信息有误,请及时联系@15-沙子森。
|
||||
#URL
|
||||
User_Register_Link: 'http://topaz.sinaapp.com/nm/v1/reg.html?token={0}'
|
||||
User_Query_Link: 'http://topaz.sinaapp.com/nm/v1/list.html?token={0}'
|
||||
User_Submit_Link: 'http://topaz.sinaapp.com/nm/v1/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
||||
User_Profile_Link: 'http://topaz.sinaapp.com/nm/v1/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}'
|
||||
Result_Page: 'http://topaz.sinaapp.com/nm/v1/result.html'
|
||||
Operator_Home_Page: '<a href="http://topaz.sinaapp.com/nm/v1/man/home.html?token={0}">CLICK HERE</a>'
|
||||
Operator_Login_Page: 'http://topaz.sinaapp.com/nm/v1/man/login.html?pkey={0}'
|
||||
User_Register_Link: 'http://topaz.sinaapp.com/nm/v2/user/reg.html?token={0}'
|
||||
User_Query_Link: 'http://topaz.sinaapp.com/nm/v2/user/list.html?token={0}'
|
||||
User_Submit_Link: 'http://topaz.sinaapp.com/nm/v2/user/rrepair.html?token={0}&name={1}&isp={2}&room={3}&block={4}&phone={5,number,#}'
|
||||
User_Profile_Link: 'http://topaz.sinaapp.com/nm/v2/user/modi.html?token={0}&name={1}&isp={2}&username={3}&block={4}&room={5}&phone={6,number,#}'
|
||||
Result_Page: 'http://topaz.sinaapp.com/nm/v2/result.html'
|
||||
Operator_Home_Page: 'http://topaz.sinaapp.com/nm/v2/man/home.html?token={0}'
|
||||
Operator_Login_Page: 'http://topaz.sinaapp.com/nm/v2/man/login.html?pkey={0}'
|
||||
|
||||
#Localized
|
||||
#Status
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
"key": "CANCEL"
|
||||
},
|
||||
{
|
||||
"type": "click",
|
||||
"type": "view",
|
||||
"name": "修改资料",
|
||||
"key": "PROFILE"
|
||||
"url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb7a8b799e494b053&redirect_uri=http%3a%2f%2fwcs.sola.love%2foauth2%2fcallback&response_type=code&scope=snsapi_base&state=PROFILE#wechat_redirect"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -34,9 +34,9 @@
|
||||
"key": "OPERATOR_INFO"
|
||||
},
|
||||
{
|
||||
"type": "click",
|
||||
"type": "view",
|
||||
"name": "后台登录",
|
||||
"key": "LOGIN"
|
||||
"url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb7a8b799e494b053&redirect_uri=http%3a%2f%2fwcs.sola.love%2foauth2%2fcallback&response_type=code&scope=snsapi_base&state=LOGIN#wechat_redirect"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
"key": "CANCEL"
|
||||
},
|
||||
{
|
||||
"type": "click",
|
||||
"type": "view",
|
||||
"name": "修改资料",
|
||||
"key": "PROFILE"
|
||||
"url": "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb7a8b799e494b053&redirect_uri=http%3a%2f%2fwcs.sola.love%2foauth2%2fcallback&response_type=code&scope=snsapi_base&state=PROFILE#wechat_redirect"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
48
src/main/webapp/META-INF/context.xml
Normal file
48
src/main/webapp/META-INF/context.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- The contents of this file will be loaded for each web application -->
|
||||
<Context swallowOutput="false" antiResourceLocking="true">
|
||||
|
||||
<!-- Default set of monitored resources -->
|
||||
<WatchedResource>WEB-INF/web.xml</WatchedResource>
|
||||
|
||||
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
|
||||
<!--
|
||||
<Manager pathname="" />
|
||||
-->
|
||||
<Resource auth="Container"
|
||||
description="C3P0 database connection pool"
|
||||
driverClass="com.mysql.jdbc.Driver"
|
||||
maxPoolSize="10"
|
||||
minPoolSize="2"
|
||||
acquireIncrement="1"
|
||||
maxIdleTime="3600"
|
||||
idleConnectionTestPeriod="1800"
|
||||
name="jdbc/netsupport"
|
||||
user="root"
|
||||
password=""
|
||||
factory="org.apache.naming.factory.BeanFactory"
|
||||
type="com.mchange.v2.c3p0.ComboPooledDataSource"
|
||||
jdbcUrl="jdbc:mysql://localhost:3306/netsupport?autoReconnect=true&characterEncoding=utf8" />
|
||||
<!-- Uncomment this to enable Comet connection tacking (provides events
|
||||
on session expiration as well as webapp lifecycle) -->
|
||||
<!--
|
||||
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
|
||||
-->
|
||||
|
||||
</Context>
|
||||
23
src/test/java/love/sola/netsupport/api/ReflectionTest.java
Normal file
23
src/test/java/love/sola/netsupport/api/ReflectionTest.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2016/3/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class ReflectionTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Reflections reflections = new Reflections(getClass().getPackage().getName());
|
||||
Set<Class<? extends API>> set = reflections.getSubTypesOf(API.class);
|
||||
assert set.size() == 14;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,18 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/3.
|
||||
* Created by Sola on 2016/3/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TestDate {
|
||||
public class ReflectionTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
System.out.println(new Date());
|
||||
public void testLang() {
|
||||
assert Lang.messages != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
package love.sola.netsupport.enums;
|
||||
|
||||
import love.sola.netsupport.enums.Block;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -9,11 +8,21 @@ import org.junit.Test;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TestReflection {
|
||||
public class ReflectionTest {
|
||||
|
||||
@Test
|
||||
public void testBlock() {
|
||||
assert Block.inverseMap != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccess() {
|
||||
assert Access.inverseMap != null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatus() {
|
||||
assert Status.inverseMap != null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import love.sola.netsupport.util.RSAUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.junit.Test;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
@@ -16,7 +15,7 @@ import java.security.spec.X509EncodedKeySpec;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TestEncrypt {
|
||||
public class EncryptTest {
|
||||
|
||||
@Test
|
||||
public void testBCrypt() {
|
||||
@@ -1,11 +1,9 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import com.google.gson.*;
|
||||
import love.sola.netsupport.config.Lang;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -14,12 +12,7 @@ import java.util.Date;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TestMessageFormat {
|
||||
|
||||
@Test
|
||||
public void testLang() {
|
||||
assert Lang.messages != null;
|
||||
}
|
||||
public class GsonTest {
|
||||
|
||||
@Test
|
||||
public void testJsonDate() {
|
||||
@@ -35,14 +28,4 @@ public class TestMessageFormat {
|
||||
assert gson.toJson(ISP.TELECOM).equals("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() {
|
||||
assert "15838838438".equals(MessageFormat.format("{0,number,#}", 15838838438L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpInfo() {
|
||||
assert !Lang.format("Operator_Info", 1541, "Sola", 0, 0, 4).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
34
src/test/java/love/sola/netsupport/util/URLEncodeTest.java
Normal file
34
src/test/java/love/sola/netsupport/util/URLEncodeTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import com.google.common.net.UrlEscapers;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2016/3/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class URLEncodeTest {
|
||||
|
||||
@Test
|
||||
public void testEncode() throws UnsupportedEncodingException {
|
||||
assertThat(
|
||||
UrlEscapers.urlFragmentEscaper().escape("Test Title"),
|
||||
equalTo("Test%20Title")
|
||||
);
|
||||
assertThat(
|
||||
Redirect.success()
|
||||
.title("Test Title")
|
||||
.msg("Test Message")
|
||||
.toString(),
|
||||
equalTo("http://topaz.sinaapp.com/nm/v2/result.html?type=1&title=Test%20Title&msg=Test%20Message&")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/26.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TestRegex {
|
||||
|
||||
public static final String STUDENT_ID_REGEX = "^(2012|2013|2014|2015)[0-9]{9}";
|
||||
|
||||
@Test
|
||||
public void testStudentId() {
|
||||
assert !"2011130201233".matches(STUDENT_ID_REGEX);
|
||||
assert "2015130201233".matches(STUDENT_ID_REGEX);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user