|
|
@ -2,6 +2,8 @@ package com.manage.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.google.code.kaptcha.Constants;
|
|
|
|
|
|
|
|
import com.google.code.kaptcha.Producer;
|
|
|
|
import com.manage.bean.LoginVoRedis;
|
|
|
|
import com.manage.bean.LoginVoRedis;
|
|
|
|
import com.manage.dao.Power_Login_SetMapper;
|
|
|
|
import com.manage.dao.Power_Login_SetMapper;
|
|
|
|
import com.manage.encrypt.Base64;
|
|
|
|
import com.manage.encrypt.Base64;
|
|
|
@ -21,13 +23,20 @@ import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
|
import sun.security.provider.MD5;
|
|
|
|
import sun.security.provider.MD5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@ -35,6 +44,9 @@ import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
@Controller
|
|
|
|
public class LoginController {
|
|
|
|
public class LoginController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private Producer captchaProducer;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${TOKEN_EXPIRE_TIME}")
|
|
|
|
@Value("${TOKEN_EXPIRE_TIME}")
|
|
|
|
private long TOKEN_EXPIRE_TIME;
|
|
|
|
private long TOKEN_EXPIRE_TIME;
|
|
|
|
@Value("${sysFlag}")
|
|
|
|
@Value("${sysFlag}")
|
|
|
@ -62,9 +74,7 @@ public class LoginController {
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${EMRMEDICALRECORD_PORT}")
|
|
|
|
@Value("${EMRMEDICALRECORD_PORT}")
|
|
|
|
private String port;
|
|
|
|
private String port;
|
|
|
|
//
|
|
|
|
|
|
|
|
// @Autowired
|
|
|
|
|
|
|
|
// private JedisPool jedisPool;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${POWER_PORT}")
|
|
|
|
@Value("${POWER_PORT}")
|
|
|
|
private String POWER_PORT;
|
|
|
|
private String POWER_PORT;
|
|
|
@ -79,21 +89,24 @@ public class LoginController {
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "login", method = RequestMethod.POST)
|
|
|
|
@RequestMapping(value = "login", method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
@ResponseBody
|
|
|
|
public Msg login(Power_User powerUser, HttpServletResponse response, HttpServletRequest request, Model model) {
|
|
|
|
public Msg login(Power_User powerUser, HttpServletResponse response, HttpServletRequest request, Model model,String code) {
|
|
|
|
|
|
|
|
//判断是否在可登录时间内
|
|
|
|
|
|
|
|
Power_Log unlockDate = logService.getUnlockDate(powerUser.getUserName());
|
|
|
|
|
|
|
|
//不等于空说明账号次数过多被锁定
|
|
|
|
|
|
|
|
if (unlockDate != null) {
|
|
|
|
|
|
|
|
return Msg.failUnlockUser(unlockDate.getUnlockDate());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//正确的验证码
|
|
|
|
|
|
|
|
String original =(String) request.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
|
|
|
|
String userName = powerUser.getUserName();
|
|
|
|
String userName = powerUser.getUserName();
|
|
|
|
String userPwd = powerUser.getUserPwd();
|
|
|
|
String userPwd = powerUser.getUserPwd();
|
|
|
|
|
|
|
|
if (!code.equalsIgnoreCase(original)) {
|
|
|
|
|
|
|
|
return Msg.codeUser();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!userName.equals("admin")) {
|
|
|
|
if (!userName.equals("admin")) {
|
|
|
|
String s = "00" + userName;
|
|
|
|
String s = "00" + userName;
|
|
|
|
powerUser.setUserName(s);
|
|
|
|
powerUser.setUserName(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Jedis redis = JedisPoolUtil.getJedisPoolInstance().getResource();
|
|
|
|
|
|
|
|
String userInfo = redis.get(userName);
|
|
|
|
|
|
|
|
String errorPwsCount = "0";
|
|
|
|
|
|
|
|
if (userInfo == null) {
|
|
|
|
|
|
|
|
redis.set(userName, errorPwsCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = Integer.parseInt(redis.get(userName));
|
|
|
|
|
|
|
|
if (i < 5) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Power_UserVo user = powerUserService.findPowerUserByUserNameAndUserPwd(powerUser);
|
|
|
|
Power_UserVo user = powerUserService.findPowerUserByUserNameAndUserPwd(powerUser);
|
|
|
|
//添加进操作日志
|
|
|
|
//添加进操作日志
|
|
|
@ -153,11 +166,9 @@ public class LoginController {
|
|
|
|
//大小写,中文,数据,特殊符号必须存在三种
|
|
|
|
//大小写,中文,数据,特殊符号必须存在三种
|
|
|
|
String reg = "^(?![A-Za-z]+$)(?![A-Z\\d]+$)(?![A-Z\\W]+$)(?![a-z\\d]+$)(?![a-z\\W]+$)(?![\\d\\W]+$)\\S{8,20}$";
|
|
|
|
String reg = "^(?![A-Za-z]+$)(?![A-Z\\d]+$)(?![A-Z\\W]+$)(?![a-z\\d]+$)(?![a-z\\W]+$)(?![\\d\\W]+$)\\S{8,20}$";
|
|
|
|
//判断是否为弱密码
|
|
|
|
//判断是否为弱密码
|
|
|
|
boolean msg=userPwd.matches(reg);
|
|
|
|
boolean msg = userPwd.matches(reg);
|
|
|
|
redis.del(userName);
|
|
|
|
if (msg == false) {
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
String url = "http://" + SERVER_IP + ":" + SERVER_PORT + "/power" + "/font/updatePassword";
|
|
|
|
if (msg==false){
|
|
|
|
|
|
|
|
String url = "http://" + SERVER_IP + ":" + SERVER_PORT +"/power"+ "/font/updatePassword";
|
|
|
|
|
|
|
|
return Msg.success().add("url", url);
|
|
|
|
return Msg.success().add("url", url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//单点登录跳转
|
|
|
|
//单点登录跳转
|
|
|
@ -186,22 +197,19 @@ public class LoginController {
|
|
|
|
log.setLogTitle("登录");
|
|
|
|
log.setLogTitle("登录");
|
|
|
|
log.setLogContent("用户密码错误");
|
|
|
|
log.setLogContent("用户密码错误");
|
|
|
|
log.setRemark("已错误【" + wrongNum + "】次");
|
|
|
|
log.setRemark("已错误【" + wrongNum + "】次");
|
|
|
|
|
|
|
|
//如果错误次数=5添加锁定时间
|
|
|
|
|
|
|
|
if (wrongNum == 5) {
|
|
|
|
|
|
|
|
SimpleDateFormat UnlockFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
log.setUnlockDate(UnlockFmt.format(new Date().getTime() + 15 * 60 * 1000));
|
|
|
|
|
|
|
|
}
|
|
|
|
logService.insert(log);
|
|
|
|
logService.insert(log);
|
|
|
|
request.setAttribute("msg", "用户名或密码不正确");
|
|
|
|
request.setAttribute("msg", "用户名或密码不正确");
|
|
|
|
redis.incr(userName);
|
|
|
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
|
|
|
return Msg.failUser();
|
|
|
|
return Msg.failUser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
CacheManager.addExcCount("exc");
|
|
|
|
CacheManager.addExcCount("exc");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//失败次数大于五时锁十五分钟
|
|
|
|
|
|
|
|
redis.setex(userName, 900, i + "");
|
|
|
|
|
|
|
|
JedisPoolUtil.close(redis);
|
|
|
|
|
|
|
|
return Msg.failUser2();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -225,4 +233,45 @@ public class LoginController {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 生成带验证码的图片
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param model
|
|
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
|
|
* @param timestamp
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* @throws IOException
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getCaptchaImage", method = RequestMethod.GET)
|
|
|
|
|
|
|
|
public ModelAndView getCaptchaImage(Model model, HttpServletRequest request, HttpServletResponse response,
|
|
|
|
|
|
|
|
@RequestParam(value = "timestamp", required = false) String timestamp) throws IOException {
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(timestamp)) {
|
|
|
|
|
|
|
|
//System.out.println("没有时间戳\ttimestamp:" + timestamp);
|
|
|
|
|
|
|
|
model.addAttribute("timestamp", System.currentTimeMillis());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//System.out.println("有时间戳\ttimestamp:" + timestamp);
|
|
|
|
|
|
|
|
model.addAttribute("timestamp", timestamp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
response.setDateHeader("Expires", 0);
|
|
|
|
|
|
|
|
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
|
|
|
|
|
|
|
|
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
|
|
|
|
|
|
|
|
response.setHeader("Pragma", "no-cache");
|
|
|
|
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
|
|
|
|
|
String capText = captchaProducer.createText();
|
|
|
|
|
|
|
|
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
|
|
|
|
|
|
|
|
BufferedImage bi = captchaProducer.createImage(capText);
|
|
|
|
|
|
|
|
ServletOutputStream out = response.getOutputStream();
|
|
|
|
|
|
|
|
ImageIO.write(bi, "jpg", out);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|