瀏覽代碼

用户上传头像实时同步缓存,无需重新登录

RuoYi 5 年之前
父節點
當前提交
018195e47b

+ 5 - 0
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -10,6 +10,11 @@ import io.jsonwebtoken.Claims;
 public class Constants
 {
     /**
+     * UTF-8 字符集
+     */
+    public static final String UTF8 = "UTF-8";
+    
+    /**
      * 通用成功标识
      */
     public static final String SUCCESS = "0";

+ 12 - 0
ruoyi/src/main/java/com/ruoyi/framework/security/service/TokenService.java

@@ -71,6 +71,18 @@ public class TokenService
     }
 
     /**
+     * 设置用户身份信息
+     */
+    public void setLoginUser(LoginUser loginUser)
+    {
+        if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken()))
+        {
+            String userKey = getTokenKey(loginUser.getToken());
+            redisCache.setCacheObject(userKey, loginUser);
+        }
+    }
+
+    /**
      * 创建令牌
      * 
      * @param loginUser 用户信息

+ 2 - 0
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java

@@ -98,6 +98,8 @@ public class SysProfileController extends BaseController
             {
                 AjaxResult ajax = AjaxResult.success();
                 ajax.put("imgUrl", avatar);
+                loginUser.getUser().setAvatar(avatar);
+                tokenService.setLoginUser(loginUser);
                 return ajax;
             }
         }