11.13每日报告
今天晚上查错,vue的项目,密码加密问题,需要用新的登录逻辑
@Override
public Map<String, Object> login(User user) {
//根据用户名查询
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getUsername,user.getUsername());
User loginUser = this.baseMapper.selectOne(wrapper);
if (loginUser!=null&&passwordEncoder.matches(user.getPassword(),loginUser.getPassword())){
//暂时用UUID ,终极方案是jwt
String key = "user:"+ UUID.randomUUID();
//存入redis
loginUser.setPassword(null);
redisTemplate.opsForValue().set(key,loginUser,30, TimeUnit.MINUTES);
//返回数据
Map<String,Object> data = new HashMap<>();
data.put("token",key);
return data;
}
// 查询结果不为空 则生成token,并且将用户信息存入redis
return null;
}
需要用passwordEncorder.matches来匹配