|
|
|
@ -27,94 +27,98 @@ public class LoginPersonController extends Controller {
|
|
|
|
|
LoginPersonModel model = new LoginPersonModel();
|
|
|
|
|
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
public void doLogin(String username, String password) {
|
|
|
|
|
public void doLogin(String username, String password, String platform) {
|
|
|
|
|
if (StrKit.isBlank(platform)) {
|
|
|
|
|
platform = "WEB";
|
|
|
|
|
}
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
if (StrKit.isBlank(username)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(password)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "密码不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(username)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(password)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "密码不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检查缓存中此账号错误了几次
|
|
|
|
|
String PassWordKey = "WrongPassWord_" + username;
|
|
|
|
|
int ErrCnt = 4; //最多允许错几次 4+1
|
|
|
|
|
int cntNum = 0; //错几次了
|
|
|
|
|
if (RedisKit.exists(PassWordKey)) cntNum = Integer.parseInt(RedisKit.get(PassWordKey).toString());
|
|
|
|
|
//检查缓存中此账号错误了几次
|
|
|
|
|
String PassWordKey = "WrongPassWord_" + username;
|
|
|
|
|
int ErrCnt = 4; //最多允许错几次 4+1
|
|
|
|
|
int cntNum = 0; //错几次了
|
|
|
|
|
if (RedisKit.exists(PassWordKey)) cntNum = Integer.parseInt(RedisKit.get(PassWordKey).toString());
|
|
|
|
|
if (cntNum > ErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "账号被停用5分钟,请稍后再试!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//与前端配合RSA通用加密解密
|
|
|
|
|
try {
|
|
|
|
|
password = RsaUtils.decryptDataOnJava(password, RsaUtils.PRIVATEKEY);
|
|
|
|
|
} catch (Exception err) {
|
|
|
|
|
password = "!@#$%^&&*^*&(*)(*_)^%^$%$^%$^%";
|
|
|
|
|
}
|
|
|
|
|
String passwordEncode = CommonUtil.getLdapPassword(password);
|
|
|
|
|
BaseModel bm = new BaseModel();
|
|
|
|
|
Map loginMap = bm.getLoginInfoByUserName(username);
|
|
|
|
|
if (loginMap == null || !passwordEncode.equals(loginMap.get("password").toString())) {
|
|
|
|
|
//扩展支持连续输入用户名密码错误,停用账号5分钟功能 2022.06.07
|
|
|
|
|
cntNum = 1;
|
|
|
|
|
if (RedisKit.exists(PassWordKey))
|
|
|
|
|
cntNum = Integer.parseInt(RedisKit.get(PassWordKey).toString()) + cntNum;
|
|
|
|
|
RedisKit.set(PassWordKey, String.valueOf(cntNum));
|
|
|
|
|
RedisKit.expire(PassWordKey, 60 * 5);
|
|
|
|
|
if (cntNum > ErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "账号被停用5分钟,请稍后再试!");
|
|
|
|
|
resultJson.put("msg", "密码连续输入" + (ErrCnt + 1) + "次全部错误,账号将被停用5分钟!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//与前端配合RSA通用加密解密
|
|
|
|
|
try {
|
|
|
|
|
password = RsaUtils.decryptDataOnJava(password, RsaUtils.PRIVATEKEY);
|
|
|
|
|
} catch (Exception err) {
|
|
|
|
|
password = "!@#$%^&&*^*&(*)(*_)^%^$%$^%$^%";
|
|
|
|
|
}
|
|
|
|
|
String passwordEncode = CommonUtil.getLdapPassword(password);
|
|
|
|
|
BaseModel bm = new BaseModel();
|
|
|
|
|
Map loginMap = bm.getLoginInfoByUserName(username);
|
|
|
|
|
if (loginMap == null || !passwordEncode.equals(loginMap.get("password").toString())) {
|
|
|
|
|
//扩展支持连续输入用户名密码错误,停用账号5分钟功能 2022.06.07
|
|
|
|
|
cntNum = 1;
|
|
|
|
|
if (RedisKit.exists(PassWordKey))
|
|
|
|
|
cntNum = Integer.parseInt(RedisKit.get(PassWordKey).toString()) + cntNum;
|
|
|
|
|
RedisKit.set(PassWordKey, String.valueOf(cntNum));
|
|
|
|
|
RedisKit.expire(PassWordKey, 60 * 5);
|
|
|
|
|
if (cntNum > ErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "密码连续输入" + (ErrCnt + 1) + "次全部错误,账号将被停用5分钟!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (cntNum == ErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名或密码连续错误,你还有1次机会,再次错误后账号将被封掉5分钟!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (cntNum == ErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名或密码错误!");
|
|
|
|
|
resultJson.put("msg", "用户名或密码连续错误,你还有1次机会,再次错误后账号将被封掉5分钟!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//去掉限制
|
|
|
|
|
RedisKit.del(PassWordKey);
|
|
|
|
|
//防止用户攻击修改Cookie
|
|
|
|
|
Map _map = new HashMap<String, String>();
|
|
|
|
|
_map.put("identity_id", loginMap.get("identity_id"));
|
|
|
|
|
_map.put("person_id", loginMap.get("person_id"));
|
|
|
|
|
_map.put("bureau_id", loginMap.get("bureau_id"));
|
|
|
|
|
|
|
|
|
|
String token = CommonUtil.Sign(_map, BaseApplication.PropKit.get("jwt.CookieMd5SingPwd"));
|
|
|
|
|
CookieUtil.set(getResponse(), "identity_id", loginMap.get("identity_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "person_id", loginMap.get("person_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "bureau_id", loginMap.get("bureau_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "token", token, false, true);
|
|
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("identity_id", loginMap.get("identity_id").toString());
|
|
|
|
|
resultJson.put("person_id", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("bureau_id", loginMap.get("bureau_id").toString());
|
|
|
|
|
resultJson.put("person_name", loginMap.get("person_name").toString());
|
|
|
|
|
//根据人员id,获取所有单位信息
|
|
|
|
|
Record r = bm.getBureauInfoByPersonId(loginMap.get("person_id").toString());
|
|
|
|
|
if (r != null) resultJson.put("bureau_name", r.getStr("bureau_name"));
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "登录异常!");
|
|
|
|
|
resultJson.put("msg", "用户名或密码错误!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//去掉限制
|
|
|
|
|
RedisKit.del(PassWordKey);
|
|
|
|
|
//防止用户攻击修改Cookie
|
|
|
|
|
Map _map = new HashMap<String, String>();
|
|
|
|
|
_map.put("identity_id", loginMap.get("identity_id"));
|
|
|
|
|
_map.put("person_id", loginMap.get("person_id"));
|
|
|
|
|
_map.put("bureau_id", loginMap.get("bureau_id"));
|
|
|
|
|
|
|
|
|
|
String token = CommonUtil.Sign(_map, BaseApplication.PropKit.get("jwt.CookieMd5SingPwd"));
|
|
|
|
|
CookieUtil.set(getResponse(), "identity_id", loginMap.get("identity_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "person_id", loginMap.get("person_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "bureau_id", loginMap.get("bureau_id").toString(), false, true);
|
|
|
|
|
CookieUtil.set(getResponse(), "token", token, false, true);
|
|
|
|
|
//添加返回的Token JWT
|
|
|
|
|
String jwtToken = JwtUtil.generateToken(Integer.parseInt(loginMap.get("identity_id").toString()), loginMap.get("person_id").toString(), loginMap.get("bureau_id").toString());
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("identity_id", loginMap.get("identity_id").toString());
|
|
|
|
|
resultJson.put("person_id", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("bureau_id", loginMap.get("bureau_id").toString());
|
|
|
|
|
resultJson.put("person_name", loginMap.get("person_name").toString());
|
|
|
|
|
resultJson.put("jwt", jwtToken);
|
|
|
|
|
//将此人员的权限信息写入Pika,如果后面的要求登录互踢,可以用来处理互踢
|
|
|
|
|
//处理逻辑就是:检查此jwt是不是在Pika中存在,存在就是系统派发出去,并且是最后一次用户在此平台登录的TOKEN
|
|
|
|
|
//如果不存在,就表示此token已过期,踢出即可。
|
|
|
|
|
RedisKit.set("jwt_" + platform + "_" + loginMap.get("person_id").toString(), jwtToken);
|
|
|
|
|
//根据人员id,获取所有单位信息
|
|
|
|
|
Record r = bm.getBureauInfoByPersonId(loginMap.get("person_id").toString());
|
|
|
|
|
if (r != null) resultJson.put("bureau_name", r.getStr("bureau_name"));
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -356,7 +360,7 @@ public class LoginPersonController extends Controller {
|
|
|
|
|
renderFile(new File(excelFile), filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static{
|
|
|
|
|
static {
|
|
|
|
|
System.setProperty("java.awt.headless", "true");
|
|
|
|
|
}
|
|
|
|
|
/*****打印帐号和输出EXCEL的功能结束*********************************************************/
|
|
|
|
|