| 
					
				 | 
			
			
				@@ -34,8 +34,7 @@ import com.ozs.system.service.ISysUserService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author ruoyi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-public class SysLoginService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class SysLoginService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TokenService tokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -56,42 +55,32 @@ public class SysLoginService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param username 用户名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param password 密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param code 验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param uuid 唯一标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param code     验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param uuid     唯一标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public String login(String username, String password, String code, String uuid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public String login(String username, String password, String code, String uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         boolean captchaEnabled = configService.selectCaptchaEnabled(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 验证码开关 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (captchaEnabled) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (captchaEnabled) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             validateCaptcha(username, code, uuid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 用户验证 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Authentication authentication = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AuthenticationContextHolder.setContext(authenticationToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             authentication = authenticationManager.authenticate(authenticationToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        catch (Exception e) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (e instanceof BadCredentialsException) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (e instanceof BadCredentialsException) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw new UserPasswordNotMatchException(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw new ServiceException(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        finally 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AuthenticationContextHolder.clearContext(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -99,7 +88,7 @@ public class SysLoginService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         LoginUser loginUser = (LoginUser) authentication.getPrincipal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       //记录登录信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //记录登录信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         recordLoginInfo(loginUser.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 生成token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return tokenService.createToken(loginUser); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -109,22 +98,19 @@ public class SysLoginService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 校验验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param username 用户名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param code 验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param uuid 唯一标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param code     验证码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param uuid     唯一标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 结果 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void validateCaptcha(String username, String code, String uuid) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void validateCaptcha(String username, String code, String uuid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String captcha = redisCache.getCacheObject(verifyKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         redisCache.deleteObject(verifyKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (captcha == null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (captcha == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new CaptchaExpireException(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!code.equalsIgnoreCase(captcha)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!code.equalsIgnoreCase(captcha)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new CaptchaException(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -135,8 +121,7 @@ public class SysLoginService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param userId 用户ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void recordLoginInfo(Long userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void recordLoginInfo(Long userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SysUser sysUser = new SysUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sysUser.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); 
			 |