From 5fd51c437819f1c9d027a936db4ba2ee7cd2e053 Mon Sep 17 00:00:00 2001 From: ustcyc <yincun@163.com> Date: 星期二, 07 一月 2025 15:02:58 +0800 Subject: [PATCH] 升级架构 --- zhitan-framework/src/main/java/com/zhitan/framework/web/service/SysLoginService.java | 70 +++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 19 deletions(-) diff --git a/zhitan-framework/src/main/java/com/zhitan/framework/web/service/SysLoginService.java b/zhitan-framework/src/main/java/com/zhitan/framework/web/service/SysLoginService.java index d881545..be2716a 100644 --- a/zhitan-framework/src/main/java/com/zhitan/framework/web/service/SysLoginService.java +++ b/zhitan-framework/src/main/java/com/zhitan/framework/web/service/SysLoginService.java @@ -1,15 +1,5 @@ package com.zhitan.framework.web.service; -import javax.annotation.Resource; - -import com.zhitan.framework.manager.AsyncManager; -import com.zhitan.framework.manager.factory.AsyncFactory; -import com.zhitan.framework.security.context.AuthenticationContextHolder; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; import com.zhitan.common.constant.CacheConstants; import com.zhitan.common.constant.Constants; import com.zhitan.common.constant.UserConstants; @@ -17,21 +7,28 @@ import com.zhitan.common.core.domain.model.LoginUser; import com.zhitan.common.core.redis.RedisCache; import com.zhitan.common.exception.ServiceException; -import com.zhitan.common.exception.user.BlackListException; -import com.zhitan.common.exception.user.CaptchaException; -import com.zhitan.common.exception.user.CaptchaExpireException; -import com.zhitan.common.exception.user.UserNotExistsException; -import com.zhitan.common.exception.user.UserPasswordNotMatchException; +import com.zhitan.common.exception.user.*; import com.zhitan.common.utils.DateUtils; import com.zhitan.common.utils.MessageUtils; import com.zhitan.common.utils.StringUtils; import com.zhitan.common.utils.ip.IpUtils; +import com.zhitan.framework.manager.AsyncManager; +import com.zhitan.framework.manager.factory.AsyncFactory; +import com.zhitan.framework.security.context.AuthenticationContextHolder; +import com.zhitan.framework.security.single.SingleAuthenticationToken; import com.zhitan.system.service.ISysConfigService; import com.zhitan.system.service.ISysUserService; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; /** * 鐧诲綍鏍¢獙鏂规硶 - * + * * @author zhitan */ @Component @@ -45,7 +42,7 @@ @Resource private RedisCache redisCache; - + @Resource private ISysUserService userService; @@ -54,7 +51,7 @@ /** * 鐧诲綍楠岃瘉 - * + * * @param username 鐢ㄦ埛鍚� * @param password 瀵嗙爜 * @param code 楠岃瘉鐮� @@ -102,7 +99,7 @@ /** * 鏍¢獙楠岃瘉鐮� - * + * * @param username 鐢ㄦ埛鍚� * @param code 楠岃瘉鐮� * @param uuid 鍞竴鏍囪瘑 @@ -178,4 +175,39 @@ sysUser.setLoginDate(DateUtils.getNowDate()); userService.updateUserProfile(sysUser); } + + + /** + * 鐧诲綍楠岃瘉 + * @param username + * @return 缁撴灉 + */ + public String loginNoCode(String username) + { + // 鐢ㄦ埛楠岃瘉 + Authentication authentication = null; + try + { + authentication = authenticationManager + .authenticate(new SingleAuthenticationToken(username)); + } + catch (Exception e) + { + if (e instanceof BadCredentialsException) + { + AsyncManager.me().execute(AsyncFactory.recordLoginInfo(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); + throw new UserPasswordNotMatchException(); + } + else + { + AsyncManager.me().execute(AsyncFactory.recordLoginInfo(username, Constants.LOGIN_FAIL, e.getMessage())); + throw new ServiceException(e.getMessage()); + } + } + AsyncManager.me().execute(AsyncFactory.recordLoginInfo(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + recordLoginInfo(loginUser.getUserId()); + // 鐢熸垚token + return tokenService.createToken(loginUser); + } } -- Gitblit v1.9.3