用户模块:用户注销
This commit is contained in:
parent
4670360495
commit
43bcec3cc0
@ -60,6 +60,16 @@ public class UserController {
|
|||||||
return R.ok(userService.getLoginUserVO(user));
|
return R.ok(userService.getLoginUserVO(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注销
|
||||||
|
*/
|
||||||
|
@PostMapping("/logout")
|
||||||
|
public R<Boolean> userLogout(HttpServletRequest request) {
|
||||||
|
ThrowUtils.throwIf(request == null, ErrorCode.PARAMS_ERROR);
|
||||||
|
boolean result = userService.userLogout(request);
|
||||||
|
return R.ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,4 +57,13 @@ public interface UserService extends IService<User> {
|
|||||||
*/
|
*/
|
||||||
User getLoginUser(HttpServletRequest request);
|
User getLoginUser(HttpServletRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户注销
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
* @return 是否注销成功
|
||||||
|
*/
|
||||||
|
boolean userLogout(HttpServletRequest request);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,19 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
|||||||
return currentUser;
|
return currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean userLogout(HttpServletRequest request) {
|
||||||
|
// 先判断是否已登录
|
||||||
|
Object userObj = request.getSession().getAttribute(UserConstant.USER_LOGIN_STATE);
|
||||||
|
if (userObj == null) {
|
||||||
|
throw new MyException(ErrorCode.OPERATION_ERROR, "未登录");
|
||||||
|
}
|
||||||
|
// 移除登录态
|
||||||
|
request.getSession().removeAttribute(UserConstant.USER_LOGIN_STATE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user