|
@@ -7,11 +7,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
|
+import org.apache.shiro.mgt.SecurityManager;
|
|
|
|
+import org.apache.shiro.subject.Subject;
|
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
import org.jeecg.common.util.RedisUtil;
|
|
import org.jeecg.common.util.RedisUtil;
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
|
+import org.jeecg.config.shiro.JwtToken;
|
|
import org.jeecg.modules.app.service.IUserService;
|
|
import org.jeecg.modules.app.service.IUserService;
|
|
import org.jeecg.modules.app.vo.LoginUserVO;
|
|
import org.jeecg.modules.app.vo.LoginUserVO;
|
|
import org.jeecg.modules.app.vo.MsgInfoVO;
|
|
import org.jeecg.modules.app.vo.MsgInfoVO;
|
|
@@ -48,6 +52,8 @@ public class UserServiceImpl implements IUserService {
|
|
@Resource
|
|
@Resource
|
|
private FamilyMembersMapper familyMembersMapper;
|
|
private FamilyMembersMapper familyMembersMapper;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ private SecurityManager securityManager;
|
|
|
|
+ @Resource
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -119,14 +125,19 @@ public class UserServiceImpl implements IUserService {
|
|
|
|
|
|
|
|
|
|
private LoginUserVO generateLoginUserVO(SysUser user) {
|
|
private LoginUserVO generateLoginUserVO(SysUser user) {
|
|
- String userAccount = user.getUsername();
|
|
|
|
- String userPassword = user.getPassword();
|
|
|
|
- // 1.生成token
|
|
|
|
- String token = JwtUtil.sign(userAccount, userPassword);
|
|
|
|
|
|
+ String token = JwtUtil.sign(user.getUsername(), user.getPassword());
|
|
// 设置token缓存有效时间
|
|
// 设置token缓存有效时间
|
|
- redisUtil.set(PREFIX_USER_TOKEN + token, token);
|
|
|
|
- redisUtil.expire(PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
|
|
|
- return new LoginUserVO().setToken(token)
|
|
|
|
|
|
+ redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
|
|
|
+ redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
|
|
|
+ // 创建 JwtToken 并登录 Subject
|
|
|
|
+ JwtToken jwtToken = new JwtToken(token);
|
|
|
|
+ Subject subject = new Subject.Builder(securityManager).buildSubject();
|
|
|
|
+ subject.login(jwtToken); // 触发 Shiro 登录流程
|
|
|
|
+ // 确保 LoginUser 可被后续获取
|
|
|
|
+ LoginUser loginUser = new LoginUser();
|
|
|
|
+ BeanUtils.copyProperties(loginUser, user);
|
|
|
|
+ return new LoginUserVO()
|
|
|
|
+ .setToken(token)
|
|
.setId(user.getId())
|
|
.setId(user.getId())
|
|
.setUserName(user.getUsername())
|
|
.setUserName(user.getUsername())
|
|
.setUserAvatar(user.getAvatar());
|
|
.setUserAvatar(user.getAvatar());
|