From ee29556679d92bdc1aa0d5951e4931d342c29c3f Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期四, 10 八月 2023 12:51:18 +0800
Subject: [PATCH] 优化首次用户登录获取不到融云token的bug
---
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 10 +++++++---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java | 1 +
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java | 26 ++++++++++++++------------
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java | 13 -------------
4 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
index 736c164..b3053e5 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
@@ -24,14 +24,13 @@
/**
* 鐧诲綍楠岃瘉
- *
+ *
* @author ruoyi
*/
@RestController
@Api(tags = "鐧诲綍楠岃瘉鎺ュ彛")
@Anonymous
-public class SysLoginController
-{
+public class SysLoginController {
@Autowired
private SysLoginService loginService;
@@ -43,14 +42,13 @@
/**
* 鐧诲綍鏂规硶
- *
+ *
* @param loginBody 鐧诲綍淇℃伅
* @return 缁撴灉
*/
@PostMapping("/login")
@ApiOperation(value = "鐧诲綍")
- public AjaxResult login(@RequestBody LoginBody loginBody)
- {
+ public AjaxResult login(@RequestBody LoginBody loginBody) {
AjaxResult ajax = AjaxResult.success();
// 鐢熸垚浠ょ墝
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
@@ -61,14 +59,19 @@
/**
* 鑾峰彇鐢ㄦ埛淇℃伅
- *
+ *
* @return 鐢ㄦ埛淇℃伅
*/
@GetMapping("getInfo")
@ApiOperation(value = "鑾峰彇鐢ㄦ埛淇℃伅")
- public AjaxResult getInfo()
- {
+ public AjaxResult getInfo() {
SysUser user = SecurityUtils.getLoginUser().getUser();
+ // 璧嬪�艰瀺浜憈oken鍒扮敤鎴蜂俊鎭�
+ String rongCloudToken = SecurityUtils.getLoginUser().getRongCloudToken();
+ if (rongCloudToken != null) {
+ user.setRongCloudToken(rongCloudToken);
+ }
+
// 瑙掕壊闆嗗悎
Set<String> roles = permissionService.getRolePermission(user);
// 鏉冮檺闆嗗悎
@@ -82,12 +85,11 @@
/**
* 鑾峰彇璺敱淇℃伅
- *
+ *
* @return 璺敱淇℃伅
*/
@GetMapping("getRouters")
- public AjaxResult getRouters()
- {
+ public AjaxResult getRouters() {
String userId = SecurityUtils.getUserId();
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
return AjaxResult.success(menuService.buildMenus(menus));
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java
index 3d6e809..b9e58c6 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginBody.java
@@ -27,19 +27,6 @@
*/
private String uuid;
- /**
- * 鏄惁APP鐢ㄦ埛
- */
- private Boolean isApp;
-
-
- public Boolean getApp() {
- return isApp;
- }
-
- public void setApp(Boolean app) {
- isApp = app;
- }
public String getUsername()
{
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
index 65f812c..f3fa8aa 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
@@ -50,6 +50,7 @@
@Autowired
private ISysConfigService configService;
+
@Resource
RongCloudService rongCloudService;
@@ -63,6 +64,8 @@
* @return 缁撴灉
*/
public String login(String username, String password, String code, String uuid) {
+
+
boolean captchaEnabled = configService.selectCaptchaEnabled();
// 楠岃瘉鐮佸紑鍏�
if (captchaEnabled) {
@@ -89,10 +92,10 @@
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
recordLoginInfo(loginUser.getUserId());
+
+ getRongCloudToken(loginUser);
// 鐢熸垚token
String token = tokenService.createToken(loginUser);
- //鑾峰彇铻嶄簯token
- getRongCloudToken(loginUser);
return token;
}
/**
@@ -134,7 +137,7 @@
*
* @param loginUser 鐧诲綍鐢ㄦ埛
*/
- public void getRongCloudToken(LoginUser loginUser) {
+ public String getRongCloudToken(LoginUser loginUser) {
try {
String userId = loginUser.getUserId();
String nickName = loginUser.getUser().getNickName();
@@ -144,6 +147,7 @@
sysUser.setUserId(userId);
sysUser.setRongCloudToken(token);
userService.updateUserProfile(sysUser);
+ return token;
} catch (Exception ex) {
throw ex;
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
index 0081723..aa41612 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
@@ -13,6 +13,7 @@
import com.ruoyi.alarm.config.domain.ArdAlarmTypeConfig;
import com.ruoyi.alarm.config.mapper.ArdAlarmTypeConfigMapper;
import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
--
Gitblit v1.9.3