Browse Source

feat: 账户封禁功能完成

master
xsx 2 years ago
parent
commit
00228b826e
  1. 14
      im-platform/src/main/java/com/bx/implatform/entity/User.java
  2. 28
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  3. 1
      im-ui/src/api/enums.js
  4. 17
      im-ui/src/view/Home.vue
  5. 23
      im-uniapp/App.vue
  6. 1
      im-uniapp/common/enums.js

14
im-platform/src/main/java/com/bx/implatform/entity/User.java

@ -74,11 +74,23 @@ public class User extends Model<User> {
@TableField("signature") @TableField("signature")
private String signature; private String signature;
/** /**
* 密码(明文) * 密码
*/ */
@TableField("password") @TableField("password")
private String password; private String password;
/**
* 是否被封禁
*/
@TableField("is_banned")
private Boolean isBanned;
/**
* 被封禁原因
*/
@TableField("reason")
private String reason;
/** /**
* 最后登录时间 * 最后登录时间
*/ */

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

@ -50,8 +50,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
@Override @Override
public LoginVO login(LoginDTO dto) { public LoginVO login(LoginDTO dto) {
User user = this.findUserByUserName(dto.getUserName()); User user = this.findUserByUserName(dto.getUserName());
if (null == user) { if (Objects.isNull(user)) {
throw new GlobalException(ResultCode.PROGRAM_ERROR, "用户不存在"); throw new GlobalException("用户不存在");
}
if (user.getIsBanned()) {
String tip = String.format("您的账号因'%s'已被管理员封禁,请联系客服!",user.getReason());
throw new GlobalException(tip);
} }
if (!passwordEncoder.matches(dto.getPassword(), user.getPassword())) { if (!passwordEncoder.matches(dto.getPassword(), user.getPassword())) {
throw new GlobalException(ResultCode.PASSWOR_ERROR); throw new GlobalException(ResultCode.PASSWOR_ERROR);
@ -61,8 +65,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
session.setUserId(user.getId()); session.setUserId(user.getId());
session.setTerminal(dto.getTerminal()); session.setTerminal(dto.getTerminal());
String strJson = JSON.toJSONString(session); String strJson = JSON.toJSONString(session);
String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(), jwtProperties.getAccessTokenSecret()); String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(),
String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(), jwtProperties.getRefreshTokenSecret()); jwtProperties.getAccessTokenSecret());
String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(),
jwtProperties.getRefreshTokenSecret());
LoginVO vo = new LoginVO(); LoginVO vo = new LoginVO();
vo.setAccessToken(accessToken); vo.setAccessToken(accessToken);
vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn());
@ -79,8 +85,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
} }
String strJson = JwtUtil.getInfo(refreshToken); String strJson = JwtUtil.getInfo(refreshToken);
Long userId = JwtUtil.getUserId(refreshToken); Long userId = JwtUtil.getUserId(refreshToken);
String accessToken = JwtUtil.sign(userId, strJson, jwtProperties.getAccessTokenExpireIn(), jwtProperties.getAccessTokenSecret()); User user = this.getById(userId);
String newRefreshToken = JwtUtil.sign(userId, strJson, jwtProperties.getRefreshTokenExpireIn(), jwtProperties.getRefreshTokenSecret()); 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(); LoginVO vo = new LoginVO();
vo.setAccessToken(accessToken); vo.setAccessToken(accessToken);
vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn()); vo.setAccessTokenExpiresIn(jwtProperties.getAccessTokenExpireIn());

1
im-ui/src/api/enums.js

@ -12,6 +12,7 @@ const MESSAGE_TYPE = {
LOADING: 30, LOADING: 30,
ACT_RT_VOICE: 40, ACT_RT_VOICE: 40,
ACT_RT_VIDEO: 41, ACT_RT_VIDEO: 41,
USER_BANNED: 50,
RTC_CALL_VOICE: 100, RTC_CALL_VOICE: 100,
RTC_CALL_VIDEO: 101, RTC_CALL_VIDEO: 101,
RTC_ACCEPT: 102, RTC_ACCEPT: 102,

17
im-ui/src/view/Home.vue

@ -107,6 +107,9 @@
} else if (cmd == 4) { } else if (cmd == 4) {
// //
this.handleGroupMessage(msgInfo); this.handleGroupMessage(msgInfo);
} else if (cmd == 5){
//
this.handleSystemMessage(msgInfo);
} }
}); });
this.$wsApi.onClose((e) => { this.$wsApi.onClose((e) => {
@ -246,6 +249,20 @@
this.playAudioTip(); 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() { onExit() {
this.$wsApi.close(3000); this.$wsApi.close(3000);
sessionStorage.removeItem("accessToken"); sessionStorage.removeItem("accessToken");

23
im-uniapp/App.vue

@ -30,7 +30,7 @@
wsApi.connect(UNI_APP.WS_URL, loginInfo.accessToken); wsApi.connect(UNI_APP.WS_URL, loginInfo.accessToken);
wsApi.onConnect(() => { wsApi.onConnect(() => {
// //
if(this.reconnecting){ if (this.reconnecting) {
this.reconnecting = false; this.reconnecting = false;
uni.showToast({ uni.showToast({
title: "已重新连接", title: "已重新连接",
@ -55,6 +55,9 @@
} else if (cmd == 4) { } else if (cmd == 4) {
// //
this.handleGroupMessage(msgInfo); this.handleGroupMessage(msgInfo);
} else if (cmd == 5) {
//
this.handleSystemMessage(msgInfo);
} }
}); });
wsApi.onClose((res) => { wsApi.onClose((res) => {
@ -189,7 +192,17 @@
// //
this.insertGroupMessage(group, msg); 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) { insertGroupMessage(group, msg) {
// //
@ -268,7 +281,7 @@
}, },
exit() { exit() {
console.log("exit"); console.log("exit");
wsApi.close(1000); wsApi.close(3099);
uni.removeStorageSync("loginInfo"); uni.removeStorageSync("loginInfo");
uni.reLaunch({ uni.reLaunch({
url: "/pages/login/login" url: "/pages/login/login"
@ -302,9 +315,9 @@
wsApi.reconnect(UNI_APP.WS_URL, loginInfo.accessToken); wsApi.reconnect(UNI_APP.WS_URL, loginInfo.accessToken);
}).catch(() => { }).catch(() => {
// 5s // 5s
setTimeout(()=>{ setTimeout(() => {
this.reconnectWs(); this.reconnectWs();
},5000) }, 5000)
}) })
}, },
reloadUserInfo() { reloadUserInfo() {

1
im-uniapp/common/enums.js

@ -13,6 +13,7 @@ const MESSAGE_TYPE = {
LOADING:30, LOADING:30,
ACT_RT_VOICE:40, ACT_RT_VOICE:40,
ACT_RT_VIDEO:41, ACT_RT_VIDEO:41,
USER_BANNED:50,
RTC_CALL_VOICE: 100, RTC_CALL_VOICE: 100,
RTC_CALL_VIDEO: 101, RTC_CALL_VIDEO: 101,
RTC_ACCEPT: 102, RTC_ACCEPT: 102,

Loading…
Cancel
Save