mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-26 04:39:26 +08:00
学员安全登出
This commit is contained in:
@@ -7,10 +7,12 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.caches.UserLoginCache;
|
||||
import xyz.playedu.api.PlayEduFCtx;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.event.UserLoginEvent;
|
||||
import xyz.playedu.api.event.UserLogoutEvent;
|
||||
import xyz.playedu.api.exception.JwtLogoutException;
|
||||
import xyz.playedu.api.exception.LimitException;
|
||||
import xyz.playedu.api.request.frontend.LoginPasswordRequest;
|
||||
import xyz.playedu.api.service.JWTService;
|
||||
@@ -40,16 +42,10 @@ public class LoginController {
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@Autowired
|
||||
private UserLoginCache userLoginCache;
|
||||
|
||||
@PostMapping("/password")
|
||||
public JsonResponse password(@RequestBody @Validated LoginPasswordRequest req) throws LimitException {
|
||||
String email = req.getEmail();
|
||||
|
||||
// 限流-限制学员10s内登录成功一次
|
||||
userLoginCache.check(email);
|
||||
|
||||
User user = userService.find(email);
|
||||
if (user == null) {
|
||||
return JsonResponse.error("邮箱或密码错误");
|
||||
@@ -72,4 +68,11 @@ public class LoginController {
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public JsonResponse logout() throws JwtLogoutException {
|
||||
jwtService.userLogout(PlayEduFCtx.getToken());
|
||||
ctx.publishEvent(new UserLogoutEvent(this, PlayEduFCtx.getUserId(), PlayEduFCtx.getJwtJti()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user