|  |  |  | 
|---|
|  |  |  | package com.ruoyi.framework.web.service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.ruoyi.rongcloud.service.RongCloudService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.scheduling.annotation.Async; | 
|---|
|  |  |  | import org.springframework.security.authentication.AuthenticationManager; | 
|---|
|  |  |  | import org.springframework.security.authentication.BadCredentialsException; | 
|---|
|  |  |  | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class SysLoginService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否允许账户多终端同时登录(true允许 false不允许) | 
|---|
|  |  |  | @Value("${token.soloLogin}") | 
|---|
|  |  |  | private boolean soloLogin; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String login(String username, String password, String code, String uuid) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean captchaEnabled = configService.selectCaptchaEnabled(); | 
|---|
|  |  |  | // 验证码开关 | 
|---|
|  |  |  | if (captchaEnabled) { | 
|---|
|  |  |  | 
|---|
|  |  |  | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); | 
|---|
|  |  |  | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); | 
|---|
|  |  |  | recordLoginInfo(loginUser.getUserId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!soloLogin) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 如果用户不允许多终端同时登录,清除缓存信息 | 
|---|
|  |  |  | String userIdKey = Constants.LOGIN_USERID_KEY + loginUser.getUser().getUserId(); | 
|---|
|  |  |  | String userKey = redisCache.getCacheObject(userIdKey); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(userKey)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | redisCache.deleteObject(userIdKey); | 
|---|
|  |  |  | redisCache.deleteObject(userKey); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | getRongCloudToken(loginUser); | 
|---|
|  |  |  | // 生成token | 
|---|
|  |  |  | String token = tokenService.createToken(loginUser); | 
|---|
|  |  |  | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param loginUser 登录用户 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Async | 
|---|
|  |  |  | public String getRongCloudToken(LoginUser loginUser) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String userId = loginUser.getUserId(); | 
|---|