add system operator agent

This commit is contained in:
Sola
2015-12-12 23:45:16 +08:00
parent 19f68c1e33
commit abb8891152
6 changed files with 67 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package love.sola.netsupport.api.admin;
import com.google.gson.Gson; import com.google.gson.Gson;
import love.sola.netsupport.api.Response; import love.sola.netsupport.api.Response;
import love.sola.netsupport.enums.Access;
import love.sola.netsupport.pojo.Operator; import love.sola.netsupport.pojo.Operator;
import love.sola.netsupport.sql.SQLCore; import love.sola.netsupport.sql.SQLCore;
import love.sola.netsupport.util.Checker; import love.sola.netsupport.util.Checker;
@@ -52,7 +53,8 @@ public class Login extends HttpServlet {
try (Session s = SQLCore.sf.openSession()) { try (Session s = SQLCore.sf.openSession()) {
Operator operator = s.get(Operator.class, Integer.parseInt(opId)); 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())) if (!wechat.equals(operator.getWechat()))
return new Response(Response.ResponseCode.INCORRECT_WECHAT); return new Response(Response.ResponseCode.INCORRECT_WECHAT);
if (!Crypto.check(password,operator.getPassword())) if (!Crypto.check(password,operator.getPassword()))

View 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;
}
}

View File

@@ -32,10 +32,15 @@ public class Operator {
private String name; private String name;
@Column(name = "access", nullable = false, insertable = false, updatable = false) @Column(name = "access", nullable = false, insertable = false, updatable = false)
private Integer access; private Integer access;
@Column(name = "wechat", nullable = false, insertable = false, updatable = false) @Column(name = "wechat", insertable = false, updatable = false)
private String wechat; private String wechat;
private Integer block; private Integer block;
private Integer week; private Integer week;
private String password; private String password;
//System Accounts
public static Operator USER_SELF;
public static Operator ADMIN;
} }

View File

@@ -37,6 +37,8 @@ public class SQLCore {
sr = new StandardServiceRegistryBuilder().configure().build(); sr = new StandardServiceRegistryBuilder().configure().build();
sf = new MetadataSources(sr).buildMetadata().buildSessionFactory(); sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
TableOperator.init();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -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);
}
}
} }

View File

@@ -1,6 +1,7 @@
package love.sola.netsupport.wechat.handler; package love.sola.netsupport.wechat.handler;
import love.sola.netsupport.enums.Status; import love.sola.netsupport.enums.Status;
import love.sola.netsupport.pojo.Operator;
import love.sola.netsupport.pojo.Ticket; import love.sola.netsupport.pojo.Ticket;
import love.sola.netsupport.pojo.User; import love.sola.netsupport.pojo.User;
import love.sola.netsupport.sql.SQLCore; import love.sola.netsupport.sql.SQLCore;
@@ -39,6 +40,7 @@ public class CancelHandler implements WxMpMessageHandler {
.content(lang("No_Open_Ticket_Available")).build(); .content(lang("No_Open_Ticket_Available")).build();
} }
try (Session s = SQLCore.sf.openSession()) { try (Session s = SQLCore.sf.openSession()) {
t.setOperator(Operator.USER_SELF);
t.setUpdateTime(new Date()); t.setUpdateTime(new Date());
t.setRemark(lang("User_Cancel_Remark")); t.setRemark(lang("User_Cancel_Remark"));
t.setStatus(Status.SOLVED); t.setStatus(Status.SOLVED);