Browse Source

修复用户被封禁还能登陆的bug

master
xsx 1 year ago
parent
commit
c49f3c90eb
  1. 2
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  2. 29
      im-uniapp/App.vue
  3. 1
      im-uniapp/common/request.js
  4. 1
      im-uniapp/pages/login/login.vue
  5. 1
      im-uniapp/pages/register/register.vue
  6. 4
      im-web/src/view/Home.vue

2
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -81,7 +81,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
public LoginVO refreshToken(String refreshToken) {
//验证 token
if (!JwtUtil.checkSign(refreshToken, jwtProperties.getRefreshTokenSecret())) {
throw new GlobalException("refreshToken无效或已过期");
throw new GlobalException("您的登陆信息已过期,请重新登陆");
}
String strJson = JwtUtil.getInfo(refreshToken);
Long userId = JwtUtil.getUserId(refreshToken);

29
im-uniapp/App.vue

@ -307,11 +307,24 @@
// this.audioTip.src = "/static/audio/tip.wav";
// this.audioTip.play();
},
isExpired(loginInfo) {
if (!loginInfo || !loginInfo.expireTime) {
return true;
}
return loginInfo.expireTime < new Date().getTime();
refreshToken(loginInfo) {
return new Promise((resolve, reject) => {
if (!loginInfo || !loginInfo.refreshToken) {
reject();
}
http({
url: '/refreshToken',
method: 'PUT',
header: {
refreshToken: loginInfo.refreshToken
}
}).then((newLoginInfo) => {
uni.setStorageSync("loginInfo", newLoginInfo)
resolve()
}).catch((e) => {
reject(e)
})
})
},
reconnectWs() {
// 退
@ -348,21 +361,21 @@
this.$mountStore();
//
let loginInfo = uni.getStorageSync("loginInfo")
if (!this.isExpired(loginInfo)) {
this.refreshToken(loginInfo).then(() => {
//
this.init();
//
uni.switchTab({
url: "/pages/chat/chat"
})
} else {
}).catch(() => {
//
// #ifdef H5
uni.navigateTo({
url: "/pages/login/login"
})
// #endif
}
})
}
}
</script>

1
im-uniapp/common/request.js

@ -42,7 +42,6 @@ const request = (options) => {
return;
}
let newInfo = res.data.data;
newInfo.expireTime = new Date().getTime() + newInfo.refreshTokenExpiresIn*1000;
uni.setStorageSync("loginInfo", newInfo);
requestList.forEach(cb => cb());
requestList = [];

1
im-uniapp/pages/login/login.vue

@ -51,7 +51,6 @@
console.log("登录成功,自动跳转到聊天页面...")
uni.setStorageSync("userName", this.loginForm.userName);
uni.setStorageSync("password", this.loginForm.password);
loginInfo.expireTime = new Date().getTime() + loginInfo.refreshTokenExpiresIn * 1000;
uni.setStorageSync("loginInfo", loginInfo);
// App.vue
getApp().$vm.init()

1
im-uniapp/pages/register/register.vue

@ -96,7 +96,6 @@
console.log("登录成功,自动跳转到聊天页面...")
uni.setStorageSync("userName", loginForm.userName);
uni.setStorageSync("password", loginForm.password);
loginInfo.expireTime = new Date().getTime() + loginInfo.refreshTokenExpiresIn * 1000;
uni.setStorageSync("loginInfo", loginInfo);
// App.vue
getApp().init()

4
im-web/src/view/Home.vue

@ -178,7 +178,6 @@
})
},
insertPrivateMessage(friend, msg) {
let chatInfo = {
type: 'PRIVATE',
targetId: friend.id,
@ -238,7 +237,6 @@
})
},
insertGroupMessage(group, msg) {
let chatInfo = {
type: 'GROUP',
targetId: group.id,
@ -257,7 +255,6 @@
},
handleSystemMessage(msg){
//
if (msg.type == this.$enums.MESSAGE_TYPE.USER_BANNED) {
this.$wsApi.close(3000);
this.$alert("您的账号已被管理员封禁,原因:"+ msg.content, "账号被封禁", {
@ -287,7 +284,6 @@
audio.src = url;
audio.play();
}
},
showSetting() {
this.showSettingDialog = true;

Loading…
Cancel
Save