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. 17
      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")
private String signature;
/**
* 密码(明文)
* 密码
*/
@TableField("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
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<UserMapper, User> 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<UserMapper, User> 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());

1
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,

17
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");

17
im-uniapp/App.vue

@ -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"

1
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,

Loading…
Cancel
Save