|  | @@ -5,6 +5,7 @@ import com.google.code.kaptcha.Producer;
 | 
	
		
			
				|  |  |  import com.kmall.common.annotation.SysLog;
 | 
	
		
			
				|  |  |  import com.kmall.common.utils.R;
 | 
	
		
			
				|  |  |  import com.kmall.common.utils.ShiroUtils;
 | 
	
		
			
				|  |  | +import com.kmall.common.utils.redis.JedisUtil;
 | 
	
		
			
				|  |  |  import org.apache.shiro.authc.*;
 | 
	
		
			
				|  |  |  import org.apache.shiro.crypto.hash.Sha256Hash;
 | 
	
		
			
				|  |  |  import org.apache.shiro.subject.Subject;
 | 
	
	
		
			
				|  | @@ -17,7 +18,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
 | 
	
		
			
				|  |  |  import javax.imageio.ImageIO;
 | 
	
		
			
				|  |  |  import javax.servlet.ServletException;
 | 
	
		
			
				|  |  |  import javax.servlet.ServletOutputStream;
 | 
	
		
			
				|  |  | +import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  | +import javax.servlet.http.HttpSession;
 | 
	
		
			
				|  |  |  import java.awt.image.BufferedImage;
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
		
			
				|  |  |  import java.util.HashSet;
 | 
	
	
		
			
				|  | @@ -34,9 +37,10 @@ import java.util.Set;
 | 
	
		
			
				|  |  |  public class SysLoginController {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private Producer producer;
 | 
	
		
			
				|  |  | +    public static int wsTokenExpireTime = 3600 * 24 * 30;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @RequestMapping("captcha.jpg")
 | 
	
		
			
				|  |  | -    public void captcha(HttpServletResponse response) throws ServletException, IOException {
 | 
	
		
			
				|  |  | +    public void captcha(HttpServletResponse response, HttpSession session) throws ServletException, IOException {
 | 
	
		
			
				|  |  |          response.setHeader("Cache-Control", "no-store, no-cache");
 | 
	
		
			
				|  |  |          response.setContentType("image/jpeg");
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -45,7 +49,7 @@ public class SysLoginController {
 | 
	
		
			
				|  |  |          //生成图片验证码
 | 
	
		
			
				|  |  |          BufferedImage image = producer.createImage(text);
 | 
	
		
			
				|  |  |          //保存到shiro session
 | 
	
		
			
				|  |  | -        ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
 | 
	
		
			
				|  |  | +        JedisUtil.set(Constants.KAPTCHA_SESSION_KEY, text, wsTokenExpireTime);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ServletOutputStream out = response.getOutputStream();
 | 
	
		
			
				|  |  |          ImageIO.write(image, "jpg", out);
 | 
	
	
		
			
				|  | @@ -57,8 +61,10 @@ public class SysLoginController {
 | 
	
		
			
				|  |  |      @SysLog("登录")
 | 
	
		
			
				|  |  |      @ResponseBody
 | 
	
		
			
				|  |  |      @RequestMapping(value = "/sys/login", method = RequestMethod.POST)
 | 
	
		
			
				|  |  | -    public R login(String username, String password, String captcha) throws IOException {
 | 
	
		
			
				|  |  | -        String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
 | 
	
		
			
				|  |  | +    public R login(String username, String password, String captcha,HttpSession session) throws IOException {
 | 
	
		
			
				|  |  | +        String kaptcha = (String) JedisUtil.get(Constants.KAPTCHA_SESSION_KEY);
 | 
	
		
			
				|  |  | +        System.out.println(kaptcha);
 | 
	
		
			
				|  |  | +        JedisUtil.del(Constants.KAPTCHA_SESSION_KEY);
 | 
	
		
			
				|  |  |          if (!captcha.equalsIgnoreCase(kaptcha)) {
 | 
	
		
			
				|  |  |              return R.error("验证码不正确");
 | 
	
		
			
				|  |  |          }
 |