mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
add system operator agent
This commit is contained in:
@@ -2,6 +2,7 @@ package love.sola.netsupport.api.admin;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.api.Response;
|
||||
import love.sola.netsupport.enums.Access;
|
||||
import love.sola.netsupport.pojo.Operator;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.Checker;
|
||||
@@ -52,7 +53,8 @@ public class Login extends HttpServlet {
|
||||
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
Operator operator = s.get(Operator.class, Integer.parseInt(opId));
|
||||
if (operator == null) return new Response(Response.ResponseCode.OPERATOR_NOT_FOUND);
|
||||
if (operator == null || operator.getAccess() == Access.NOLOGIN)
|
||||
return new Response(Response.ResponseCode.OPERATOR_NOT_FOUND);
|
||||
if (!wechat.equals(operator.getWechat()))
|
||||
return new Response(Response.ResponseCode.INCORRECT_WECHAT);
|
||||
if (!Crypto.check(password,operator.getPassword()))
|
||||
|
||||
42
src/main/java/love/sola/netsupport/enums/Access.java
Normal file
42
src/main/java/love/sola/netsupport/enums/Access.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package love.sola.netsupport.enums;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/6.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class Access {
|
||||
|
||||
public static final int ROOT = 0;
|
||||
public static final int NOLOGIN = 9;
|
||||
|
||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||
|
||||
static{
|
||||
System.out.println("Loading Access...");
|
||||
for (Field field : Access.class.getDeclaredFields()) {
|
||||
if (field.getType().isAssignableFrom(Integer.TYPE)) {
|
||||
try {
|
||||
inverseMap.put((Integer) field.get(null), field.getName());
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLocalized(int access) {
|
||||
if (inverseMap.containsKey(access)) {
|
||||
return lang("ACCESS_" + inverseMap.get(access));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,10 +32,15 @@ public class Operator {
|
||||
private String name;
|
||||
@Column(name = "access", nullable = false, insertable = false, updatable = false)
|
||||
private Integer access;
|
||||
@Column(name = "wechat", nullable = false, insertable = false, updatable = false)
|
||||
@Column(name = "wechat", insertable = false, updatable = false)
|
||||
private String wechat;
|
||||
private Integer block;
|
||||
private Integer week;
|
||||
private String password;
|
||||
|
||||
|
||||
//System Accounts
|
||||
public static Operator USER_SELF;
|
||||
public static Operator ADMIN;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ public class SQLCore {
|
||||
|
||||
sr = new StandardServiceRegistryBuilder().configure().build();
|
||||
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
|
||||
|
||||
TableOperator.init();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -22,5 +22,17 @@ public class TableOperator extends SQLCore {
|
||||
}
|
||||
}
|
||||
|
||||
public static Operator get(int id) {
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
return s.get(Operator.class, id);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void init() {
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
Operator.USER_SELF = s.get(Operator.class, -1);
|
||||
Operator.ADMIN = s.get(Operator.class, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package love.sola.netsupport.wechat.handler;
|
||||
|
||||
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.sql.SQLCore;
|
||||
@@ -39,6 +40,7 @@ public class CancelHandler implements WxMpMessageHandler {
|
||||
.content(lang("No_Open_Ticket_Available")).build();
|
||||
}
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
t.setOperator(Operator.USER_SELF);
|
||||
t.setUpdateTime(new Date());
|
||||
t.setRemark(lang("User_Cancel_Remark"));
|
||||
t.setStatus(Status.SOLVED);
|
||||
|
||||
Reference in New Issue
Block a user