diff --git a/im-platform/src/main/java/com/bx/implatform/entity/User.java b/im-platform/src/main/java/com/bx/implatform/entity/User.java index 639b43b..878310c 100644 --- a/im-platform/src/main/java/com/bx/implatform/entity/User.java +++ b/im-platform/src/main/java/com/bx/implatform/entity/User.java @@ -74,11 +74,23 @@ public class User extends Model { @TableField("signature") private String signature; /** - * 密码(明文) + * 密码 */ @TableField("password") private String password; + /** + * 是否被封禁 + */ + @TableField("is_banned") + private Boolean isBanned; + + /** + * 被封禁原因 + */ + @TableField("reason") + private String reason; + /** * 最后登录时间 */ diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java index b10bad4..7f81724 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java @@ -50,8 +50,12 @@ public class UserServiceImpl extends ServiceImpl implements IU @Override public LoginVO login(LoginDTO dto) { User user = this.findUserByUserName(dto.getUserName()); - if (null == user) { - throw new GlobalException(ResultCode.PROGRAM_ERROR, "用户不存在"); + if (Objects.isNull(user)) { + throw new GlobalException("用户不存在"); + } + if (user.getIsBanned()) { + String tip = String.format("您的账号因'%s'已被管理员封禁,请联系客服!",user.getReason()); + throw new GlobalException(tip); } if (!passwordEncoder.matches(dto.getPassword(), user.getPassword())) { throw new GlobalException(ResultCode.PASSWOR_ERROR); @@ -61,8 +65,10 @@ public class UserServiceImpl extends ServiceImpl implements IU session.setUserId(user.getId()); session.setTerminal(dto.getTerminal()); String strJson = JSON.toJSONString(session); - String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(), jwtProperties.getAccessTokenSecret()); - String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(), jwtProperties.getRefreshTokenSecret()); + String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(), + jwtProperties.getAccessTokenSecret()); + String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(), + jwtProperties.getRefreshTokenSecret()); LoginVO vo = new LoginVO(); vo.setAccessToken(accessToken); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); @@ -79,8 +85,18 @@ public class UserServiceImpl extends ServiceImpl implements IU } String strJson = JwtUtil.getInfo(refreshToken); Long userId = JwtUtil.getUserId(refreshToken); - String accessToken = JwtUtil.sign(userId, strJson, jwtProperties.getAccessTokenExpireIn(), jwtProperties.getAccessTokenSecret()); - String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(), jwtProperties.getRefreshTokenSecret()); + User user = this.getById(userId); + if (Objects.isNull(user)) { + throw new GlobalException("用户不存在"); + } + if (user.getIsBanned()) { + String tip = String.format("您的账号因'%s'被管理员封禁,请联系客服!",user.getReason()); + throw new GlobalException(tip); + } + String accessToken = + JwtUtil.sign(userId, strJson, jwtProperties.getAccessTokenExpireIn(), jwtProperties.getAccessTokenSecret()); + String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(), + jwtProperties.getRefreshTokenSecret()); LoginVO vo = new LoginVO(); vo.setAccessToken(accessToken); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); diff --git a/im-ui/src/api/enums.js b/im-ui/src/api/enums.js index 0fcb7eb..efdaa01 100644 --- a/im-ui/src/api/enums.js +++ b/im-ui/src/api/enums.js @@ -12,6 +12,7 @@ const MESSAGE_TYPE = { LOADING: 30, ACT_RT_VOICE: 40, ACT_RT_VIDEO: 41, + USER_BANNED: 50, RTC_CALL_VOICE: 100, RTC_CALL_VIDEO: 101, RTC_ACCEPT: 102, diff --git a/im-ui/src/view/Home.vue b/im-ui/src/view/Home.vue index 7feb810..bc6549f 100644 --- a/im-ui/src/view/Home.vue +++ b/im-ui/src/view/Home.vue @@ -107,6 +107,9 @@ } else if (cmd == 4) { // 插入群聊消息 this.handleGroupMessage(msgInfo); + } else if (cmd == 5){ + // 处理系统消息 + this.handleSystemMessage(msgInfo); } }); this.$wsApi.onClose((e) => { @@ -246,6 +249,20 @@ this.playAudioTip(); } }, + handleSystemMessage(msg){ + // 用户被封禁 + + if (msg.type == this.$enums.MESSAGE_TYPE.USER_BANNED) { + this.$wsApi.close(3000); + this.$alert("您的账号已被管理员封禁,原因:"+ msg.content, "账号被封禁", { + confirmButtonText: '确定', + callback: action => { + this.onExit(); + } + }); + return; + } + }, onExit() { this.$wsApi.close(3000); sessionStorage.removeItem("accessToken"); diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 549bf4e..432ec85 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -30,7 +30,7 @@ wsApi.connect(UNI_APP.WS_URL, loginInfo.accessToken); wsApi.onConnect(() => { // 重连成功提示 - if(this.reconnecting){ + if (this.reconnecting) { this.reconnecting = false; uni.showToast({ title: "已重新连接", @@ -55,6 +55,9 @@ } else if (cmd == 4) { // 群聊消息 this.handleGroupMessage(msgInfo); + } else if (cmd == 5) { + // 系统消息 + this.handleSystemMessage(msgInfo); } }); wsApi.onClose((res) => { @@ -189,7 +192,17 @@ // 插入群聊消息 this.insertGroupMessage(group, msg); }) - + }, + handleSystemMessage(msg) { + if (msg.type == enums.MESSAGE_TYPE.USER_BANNED) { + // 用户被封禁 + wsApi.close(3099); + uni.showModal({ + content: '您的账号已被管理员封禁,原因:' + msg.content, + showCancel: false, + }) + this.exit(); + } }, insertGroupMessage(group, msg) { // 群视频信令 @@ -268,7 +281,7 @@ }, exit() { console.log("exit"); - wsApi.close(1000); + wsApi.close(3099); uni.removeStorageSync("loginInfo"); uni.reLaunch({ url: "/pages/login/login" @@ -302,9 +315,9 @@ wsApi.reconnect(UNI_APP.WS_URL, loginInfo.accessToken); }).catch(() => { // 5s后重试 - setTimeout(()=>{ + setTimeout(() => { this.reconnectWs(); - },5000) + }, 5000) }) }, reloadUserInfo() { diff --git a/im-uniapp/common/enums.js b/im-uniapp/common/enums.js index 6dddc3b..d6f0c53 100644 --- a/im-uniapp/common/enums.js +++ b/im-uniapp/common/enums.js @@ -13,6 +13,7 @@ const MESSAGE_TYPE = { LOADING:30, ACT_RT_VOICE:40, ACT_RT_VIDEO:41, + USER_BANNED:50, RTC_CALL_VOICE: 100, RTC_CALL_VIDEO: 101, RTC_ACCEPT: 102,