Commit 846779fb9b8a0d41e0f9f2f5ffe5180d7dbf7ba3
1 parent
28789cd5
用户名登陆
Showing
1 changed file
with
32 additions
and
21 deletions
trash-garbage/src/main/java/com/trash/garbage/service/impl/GarUserServiceImpl.java
| ... | ... | @@ -140,29 +140,40 @@ public class GarUserServiceImpl extends ServiceImpl<GarUserMapper, GarUser> |
| 140 | 140 | throw new BizException(ResultCode.CODE_500, "解密失败"); |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | - | |
| 144 | - // 查询用户 | |
| 145 | - QueryWrapper<GarUser> qw = new QueryWrapper<>(); | |
| 143 | + | |
| 146 | 144 | GarUser nUser = null; |
| 147 | - qw.lambda().eq(GarUser::getGarUserTel, loginDto.getTel()); | |
| 148 | - if(loginDto.getCode() == null && loginDto.getPassword() != null){ | |
| 149 | - qw.lambda().eq(GarUser::getGarUserTel, loginDto.getTel()); | |
| 150 | - if(loginDto.getSignin() != 1){ | |
| 151 | - nUser = this.getOne(qw); | |
| 152 | - if (Objects.isNull(nUser)) { | |
| 153 | - throw new UsernameNotFoundException("当前用户不存在!"); | |
| 154 | - } | |
| 155 | - if(!new BCryptPasswordEncoder().matches(loginDto.getPassword(),nUser.getPassword())){ | |
| 156 | - throw new UsernameNotFoundException("密码错误!"); | |
| 157 | - } | |
| 158 | - } | |
| 159 | - }else{ | |
| 160 | - // 验证码验证 | |
| 161 | - String code = redisCache.getCacheObject(GlobalRedisProperties.REDIS_USER_CODE.getValue() + loginDto.getTel()); | |
| 162 | - if (loginDto.getCode() == null || !loginDto.getCode().equals(code)) { | |
| 163 | - throw new BizException(ResultCode.CODE_400, "验证码错误!!"); | |
| 164 | - } | |
| 145 | + if (StringUtils.isNotEmpty(loginDto.getNickname())) { | |
| 146 | + QueryWrapper<GarUser> qw = new QueryWrapper<>(); | |
| 147 | + qw.lambda().eq(GarUser::getGarUserName, loginDto.getNickname()); | |
| 165 | 148 | nUser = this.getOne(qw); |
| 149 | + if (Objects.isNull(nUser)) { | |
| 150 | + throw new UsernameNotFoundException("当前用户不存在!"); | |
| 151 | + } | |
| 152 | + if (!new BCryptPasswordEncoder().matches(loginDto.getPassword(), nUser.getPassword())) { | |
| 153 | + throw new UsernameNotFoundException("密码错误!"); | |
| 154 | + } | |
| 155 | + loginDto.setTel(nUser.getGarUserTel()); | |
| 156 | + } else { | |
| 157 | + QueryWrapper<GarUser> qw = new QueryWrapper<>(); | |
| 158 | + qw.lambda().eq(GarUser::getGarUserTel, loginDto.getTel()); | |
| 159 | + if(loginDto.getCode() == null && loginDto.getPassword() != null){ | |
| 160 | + qw.lambda().eq(GarUser::getGarUserTel, loginDto.getTel()); | |
| 161 | + if(loginDto.getSignin() != 1){ | |
| 162 | + nUser = this.getOne(qw); | |
| 163 | + if (Objects.isNull(nUser)) { | |
| 164 | + throw new UsernameNotFoundException("当前用户不存在!"); | |
| 165 | + } | |
| 166 | + if(!new BCryptPasswordEncoder().matches(loginDto.getPassword(),nUser.getPassword())){ | |
| 167 | + throw new UsernameNotFoundException("密码错误!"); | |
| 168 | + } | |
| 169 | + } | |
| 170 | + }else{ | |
| 171 | + String code = redisCache.getCacheObject(GlobalRedisProperties.REDIS_USER_CODE.getValue() + loginDto.getTel()); | |
| 172 | + if (loginDto.getCode() == null || !loginDto.getCode().equals(code)) { | |
| 173 | + throw new BizException(ResultCode.CODE_400, "验证码错误!!"); | |
| 174 | + } | |
| 175 | + nUser = this.getOne(qw); | |
| 176 | + } | |
| 166 | 177 | } |
| 167 | 178 | |
| 168 | 179 | if (Objects.isNull(nUser)) { | ... | ... |