|
|
|
@ -31,59 +31,9 @@ public class LoginPersonController extends Controller {
|
|
|
|
|
LoginPersonModel model = new LoginPersonModel();
|
|
|
|
|
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
public void doLogin(String username, String password, String captcha) {
|
|
|
|
|
public void doLogin(String username, String password) {
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
if (StrKit.isBlank(captcha)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "验证码不能为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (getSession().getAttribute("captcha") == null) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "在浏览器会话中没有检查到验证码,你的行为将会记录!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String memory_captcha = getSession().getAttribute("captcha").toString().toLowerCase();
|
|
|
|
|
|
|
|
|
|
//验证码错误次数
|
|
|
|
|
String checkCodeKey = "Yzm_error_" + username;
|
|
|
|
|
int CheckCodeErrCnt = 4; //最多允许错几次 4+1
|
|
|
|
|
int CheckCodecntNum = 0; //错几次了
|
|
|
|
|
if (Redis.use().exists(checkCodeKey))
|
|
|
|
|
CheckCodecntNum = Integer.parseInt(Redis.use().get(checkCodeKey).toString());
|
|
|
|
|
if (CheckCodecntNum > CheckCodeErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "账号已被停用5分钟,请稍后再试!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!memory_captcha.equals(captcha.toLowerCase())) {
|
|
|
|
|
CheckCodecntNum = 1;
|
|
|
|
|
if (Redis.use().exists(checkCodeKey))
|
|
|
|
|
CheckCodecntNum = Integer.parseInt(Redis.use().get(checkCodeKey).toString()) + CheckCodecntNum;
|
|
|
|
|
Redis.use().set(checkCodeKey, String.valueOf(CheckCodecntNum));
|
|
|
|
|
Redis.use().expire(checkCodeKey, 60 * 5);
|
|
|
|
|
|
|
|
|
|
if (CheckCodecntNum == CheckCodeErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "验证码连续输入错误" + CheckCodecntNum + "次,再错误一次将被封号5分钟!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (CheckCodecntNum > CheckCodeErrCnt) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "验证码连续输入错误5次,账号被停用5分钟,请稍后再试!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "验证码不正确!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(username)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名不允许为空!");
|
|
|
|
@ -143,7 +93,6 @@ public class LoginPersonController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
//去掉限制
|
|
|
|
|
Redis.use().del(PassWordKey);
|
|
|
|
|
Redis.use().del(checkCodeKey);
|
|
|
|
|
//防止用户攻击修改Cookie
|
|
|
|
|
Map _map = new HashMap<String, String>();
|
|
|
|
|
_map.put("identity_id", loginMap.get("identity_id"));
|
|
|
|
@ -419,29 +368,4 @@ public class LoginPersonController extends Controller {
|
|
|
|
|
System.setProperty("java.awt.headless", "true");
|
|
|
|
|
}
|
|
|
|
|
/*****打印帐号和输出EXCEL的功能结束*********************************************************/
|
|
|
|
|
// /dsBase/loginPerson/getCaptcha
|
|
|
|
|
@Before({GET.class})
|
|
|
|
|
public void getCaptcha() {
|
|
|
|
|
HttpServletResponse response = getResponse();
|
|
|
|
|
// 设置相应类型,告诉浏览器输出的内容为图片
|
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
|
// 不缓存此内容
|
|
|
|
|
response.setHeader("Pragma", "No-cache");
|
|
|
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
|
|
|
response.setDateHeader("Expire", 0);
|
|
|
|
|
try {
|
|
|
|
|
HttpSession session = getRequest().getSession();
|
|
|
|
|
LineCaptcha captcha = CaptchaUtil.createLineCaptcha(80, 42, 4, 10);
|
|
|
|
|
// 重新生成code
|
|
|
|
|
captcha.createCode();
|
|
|
|
|
//写入session
|
|
|
|
|
session.removeAttribute("captcha");
|
|
|
|
|
session.setAttribute("captcha", captcha.getCode());
|
|
|
|
|
// 将内存中的图片通过流动形式输出到客户端
|
|
|
|
|
captcha.write(response.getOutputStream());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
renderNull();
|
|
|
|
|
}
|
|
|
|
|
}
|