|
@@ -2,7 +2,9 @@ package com.sf.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.sf.dto.req.UserLoginReqDto;
|
|
|
import com.sf.dto.req.UserRegisterReqDto;
|
|
|
+import com.sf.dto.resp.UserLoginRespDto;
|
|
|
import com.sf.dto.resp.UserRegisterRespDto;
|
|
|
import com.sf.dto.resp.VerifyCodeRespDto;
|
|
|
import com.sf.po.UserInfo;
|
|
@@ -69,6 +71,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
|
|
respDto.setType(2);
|
|
|
return respDto;
|
|
|
}
|
|
|
+ map.remove(sessionId);
|
|
|
|
|
|
// 密码往往是通过md5进行加密存储
|
|
|
// DigestUtils是spring提供的工具类 需要的参数是字节数组
|
|
@@ -90,7 +93,46 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
|
|
|
|
|
respDto.setType(0);
|
|
|
respDto.setUid(userInfo.getId());
|
|
|
- respDto.setToken(userInfo.getId().toString());
|
|
|
+ respDto.setToken("token_" + userInfo.getId());
|
|
|
return respDto;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserLoginRespDto login(UserLoginReqDto reqDto) {
|
|
|
+ // 验证两个条件
|
|
|
+ // 1、用户名是否存在
|
|
|
+ // 2、密码是否正确
|
|
|
+
|
|
|
+ // 用户名或密码有一个不正确
|
|
|
+ // select * from user_info where username = '13654561111' and password = 'e10adc3949ba59abbe56e057f20f883e'
|
|
|
+ String password = DigestUtils.md5DigestAsHex(reqDto.getPassword().getBytes(StandardCharsets.UTF_8));
|
|
|
+ LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(UserInfo::getUsername, reqDto.getUsername()).eq(UserInfo::getPassword, password);
|
|
|
+ UserInfo userInfo = userInfoMapper.selectOne(lambdaQueryWrapper);
|
|
|
+
|
|
|
+ // 如果成功 直接返回成功的数据
|
|
|
+ if (userInfo != null) {
|
|
|
+ return UserLoginRespDto.builder()
|
|
|
+ .type(0)
|
|
|
+ .uid(userInfo.getId())
|
|
|
+ .nickName(userInfo.getNickName())
|
|
|
+ .token("token_" + userInfo.getId())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果失败 再区分不同的失败原因
|
|
|
+ // select count(*) from user_info where username = '13654561111'
|
|
|
+
|
|
|
+ Long count = userInfoMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<UserInfo>().eq(
|
|
|
+ UserInfo::getUsername, reqDto.getUsername()));
|
|
|
+ if (count == 0) {
|
|
|
+ // 用户名不存在
|
|
|
+ return UserLoginRespDto.builder().type(1).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码错误
|
|
|
+ return UserLoginRespDto.builder().type(2).build();
|
|
|
+
|
|
|
+ }
|
|
|
}
|