| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.entity.TTenantResp; |
| | | import com.ruoyi.common.core.domain.model.LoginUserApplet; |
| | | import com.ruoyi.common.enums.UserStatus; |
| | | import com.ruoyi.system.model.TTenant; |
| | | import com.ruoyi.system.service.TTenantService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | |
| | | |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private TTenantService tenantService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService configService; |
| | |
| | | */ |
| | | public LoginUser loginCode(String username,String code) |
| | | { |
| | | |
| | | |
| | | // 登录前置校验 |
| | | if (StringUtils.isEmpty(username)){ |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); |
| | |
| | | return loginUser; |
| | | } |
| | | |
| | | /** |
| | | * 登录验证 |
| | | * |
| | | * @param username 用户名 |
| | | * @param code 验证码 |
| | | * @return 结果 |
| | | */ |
| | | public LoginUserApplet loginCodeApplet(String username, String code) |
| | | { |
| | | // 登录前置校验 |
| | | if (StringUtils.isEmpty(username)){ |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); |
| | | throw new UserNotExistsException(); |
| | | } |
| | | // 用户验证 |
| | | TTenant user = tenantService.getOne(Wrappers.<TTenant>lambdaQuery().eq(TTenant::getAccount,username)); |
| | | if (StringUtils.isNull(user)){ |
| | | log.info("登录用户:{} 不存在.", username); |
| | | throw new ServiceException(MessageUtils.message("user.not.exists")); |
| | | } else if (user.getDisabled()) { |
| | | log.info("登录用户:{} 已被删除.", username); |
| | | throw new ServiceException(MessageUtils.message("user.password.delete")); |
| | | } |
| | | // 校验验证码 |
| | | Object cacheObject = redisCache.getCacheObject(user.getAccount()); |
| | | if(!code.equals(String.valueOf(cacheObject))){ |
| | | log.info("登录用户:{} 短信验证码错误{}", username,code); |
| | | throw new ServiceException("短信验证码错误"); |
| | | } |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| | | TTenantResp tTenantResp = new TTenantResp(); |
| | | BeanUtils.copyProperties(user,tTenantResp); |
| | | LoginUserApplet loginUser = new LoginUserApplet(user.getId(), null, tTenantResp, null); |
| | | // 生成token |
| | | return loginUser; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 校验验证码 |