feat: waitlist mode

This commit is contained in:
tim
2025-07-15 11:41:24 +08:00
parent 72236ad290
commit 5b886420c5
5 changed files with 30 additions and 8 deletions

View File

@@ -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('登录失败')

View File

@@ -185,10 +185,11 @@
<NotificationContainer :item="item" :markRead="markRead">
{{ item.fromUser.username }} 希望注册为会员理由是{{ item.content }}
<template #actions v-if="authState.role === 'ADMIN'">
<div class="optional-buttons">
<div v-if="!item.read" class="optional-buttons">
<div class="mark-approve-button-item" @click="approve(item.fromUser.id, item.id)">同意</div>
<div class="mark-reject-button-item" @click="reject(item.fromUser.id, item.id)">拒绝</div>
</div>
<div v-else class="mark-read-button-item" @click="markRead(item.id)">已读</div>
</template>
</NotificationContainer>
</template>
@@ -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('已读所有消息(注册请求除外)')
}
}

View File

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

View File

@@ -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 部署域名

View File

@@ -97,11 +97,24 @@ public class AuthController {
Optional<User> 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")