From 5b886420c59ffe1f8e25484e6d67a3707c54df70 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 15 Jul 2025 11:41:24 +0800 Subject: [PATCH] feat: waitlist mode --- open-isle-cli/src/utils/google.js | 5 +++-- open-isle-cli/src/views/MessagePageView.vue | 13 +++++++++---- .../src/views/SignupReasonPageView.vue | 2 ++ .../com/openisle/config/SecurityConfig.java | 1 + .../com/openisle/controller/AuthController.java | 17 +++++++++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/open-isle-cli/src/utils/google.js b/open-isle-cli/src/utils/google.js index 620f5c578..3dd1cd6d5 100644 --- a/open-isle-cli/src/utils/google.js +++ b/open-isle-cli/src/utils/google.js @@ -29,8 +29,9 @@ export async function googleAuthWithToken(idToken, reason, redirect) { await loadCurrentUser() toast.success('登录成功') if (redirect) redirect() - } else { - toast.error(data.error || '登录失败') + } else if (data.reason_code === 'NOT_APPROVED') { + toast.info('您的注册理由正在审批中') + if (redirect) redirect() } } catch (e) { toast.error('登录失败') diff --git a/open-isle-cli/src/views/MessagePageView.vue b/open-isle-cli/src/views/MessagePageView.vue index 85f9e3707..61e9cbb60 100644 --- a/open-isle-cli/src/views/MessagePageView.vue +++ b/open-isle-cli/src/views/MessagePageView.vue @@ -185,10 +185,11 @@ {{ item.fromUser.username }} 希望注册为会员,理由是:{{ item.content }} @@ -269,10 +270,14 @@ export default { } const markAllRead = async () => { - const ok = await markNotificationsRead(notifications.value.map(n => n.id)) + // 除了 REGISTER_REQUEST 类型消息 + const idsToMark = notifications.value.filter(n => n.type !== 'REGISTER_REQUEST').map(n => n.id) + const ok = await markNotificationsRead(idsToMark) if (ok) { - notifications.value.forEach(n => n.read = true) - toast.success('已读所有消息') + notifications.value.forEach(n => { + if (n.type !== 'REGISTER_REQUEST') n.read = true + }) + toast.success('已读所有消息(注册请求除外)') } } diff --git a/open-isle-cli/src/views/SignupReasonPageView.vue b/open-isle-cli/src/views/SignupReasonPageView.vue index 1edce1033..7faf4454f 100644 --- a/open-isle-cli/src/views/SignupReasonPageView.vue +++ b/open-isle-cli/src/views/SignupReasonPageView.vue @@ -48,12 +48,14 @@ export default { return } if (this.isGoogle) { + this.isWaitingForRegister = true const token = this.googleToken || sessionStorage.getItem('google_id_token') if (!token) { toast.error('Google 登录失败') return } await googleAuthWithToken(token, this.reason, () => { this.$router.push('/') }) + this.isWaitingForRegister = false sessionStorage.removeItem('google_id_token') return } diff --git a/src/main/java/com/openisle/config/SecurityConfig.java b/src/main/java/com/openisle/config/SecurityConfig.java index abbcef346..dae64df2d 100644 --- a/src/main/java/com/openisle/config/SecurityConfig.java +++ b/src/main/java/com/openisle/config/SecurityConfig.java @@ -71,6 +71,7 @@ public class SecurityConfig { CorsConfiguration cfg = new CorsConfiguration(); cfg.setAllowedOrigins(List.of( "http://127.0.0.1:8080", // 前端调试地址 + "http://localhost:8080", // 前端调试地址 // "http://129.204.254.110", // 前端调试地址 "https://www.open-isle.com", // 生产域名 "689d7858-openisle.cjt807916.workers.dev" // cloudflare 部署域名 diff --git a/src/main/java/com/openisle/controller/AuthController.java b/src/main/java/com/openisle/controller/AuthController.java index 5425ef1cc..62365f8a2 100644 --- a/src/main/java/com/openisle/controller/AuthController.java +++ b/src/main/java/com/openisle/controller/AuthController.java @@ -97,11 +97,24 @@ public class AuthController { Optional user = googleAuthService.authenticate(req.getIdToken(), req.getReason(), registerModeService.getRegisterMode()); if (user.isPresent()) { if (!user.get().isApproved()) { - return ResponseEntity.badRequest().body(Map.of("error", "Account awaiting approval")); + if (req.getReason() != null && !req.getReason().isEmpty()) { + // do not send empty notifition (while try login) + for (User admin : userRepository.findByRole(com.openisle.model.Role.ADMIN)) { + notificationService.createNotification(admin, NotificationType.REGISTER_REQUEST, null, null, + null, user.get(), null, req.getReason()); + } + } + return ResponseEntity.badRequest().body(Map.of( + "error", "Account awaiting approval", + "reason_code", "NOT_APPROVED" + )); } return ResponseEntity.ok(Map.of("token", jwtService.generateToken(user.get().getUsername()))); } - return ResponseEntity.badRequest().body(Map.of("error", "Invalid google token")); + return ResponseEntity.badRequest().body(Map.of( + "error", "Invalid google token", + "reason_code", "INVALID_CREDENTIALS" + )); } @GetMapping("/check")