| | |
| | | import com.ruoyi.framework.manager.AsyncManager; |
| | | import com.ruoyi.framework.manager.factory.AsyncFactory; |
| | | import com.ruoyi.framework.security.context.AuthenticationContextHolder; |
| | | import com.ruoyi.system.model.TAppUser; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TAppUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | |
| | | private ISysConfigService configService; |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | @Autowired |
| | | private TAppUserService tAppUserService; |
| | | |
| | | /** |
| | | * 登录验证 |
| | |
| | | * @param password 密码 |
| | | * @return 结果 |
| | | */ |
| | | public LoginUserApplet loginCodeApplet(String account, String password) |
| | | public LoginUserApplet loginPwdApplet(String account, String password) |
| | | { |
| | | // 登录前置校验 |
| | | if (StringUtils.isEmpty(account)){ |
| | |
| | | } |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(account, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| | | LoginUserApplet loginUser = (LoginUserApplet) authentication.getPrincipal(); |
| | | recordAppLoginInfo(loginUser.getUserId()); |
| | | recordAppLoginInfo(loginUser.getUserId().toString()); |
| | | // 生成token |
| | | 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(); |
| | | } |
| | | // 用户验证 |
| | | TAppUser user = tAppUserService.getOne(Wrappers.<TAppUser>lambdaQuery().eq(TAppUser::getPhone,username)); |
| | | if (StringUtils.isNull(user)){ |
| | | log.info("登录用户:{} 不存在.", username); |
| | | throw new ServiceException(MessageUtils.message("user.not.exists")); |
| | | } else if (user.getStatus().equals(3)) { |
| | | log.info("登录用户:{} 已被删除.", username); |
| | | throw new ServiceException(MessageUtils.message("user.password.delete")); |
| | | } |
| | | // 校验验证码 |
| | | Object cacheObject = redisCache.getCacheObject(user.getPhone()); |
| | | 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"))); |
| | | LoginUserApplet loginUser = new LoginUserApplet(user.getId(), null, null, null); |
| | | recordAppLoginInfo(loginUser.getUserId().toString()); |
| | | // 生成token |
| | | return loginUser; |
| | | } |
| | | /** |
| | | * 登录验证 |
| | | * |