mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-28 21:47:44 +08:00
feat: waitlist mode
This commit is contained in:
@@ -29,8 +29,9 @@ export async function googleAuthWithToken(idToken, reason, redirect) {
|
|||||||
await loadCurrentUser()
|
await loadCurrentUser()
|
||||||
toast.success('登录成功')
|
toast.success('登录成功')
|
||||||
if (redirect) redirect()
|
if (redirect) redirect()
|
||||||
} else {
|
} else if (data.reason_code === 'NOT_APPROVED') {
|
||||||
toast.error(data.error || '登录失败')
|
toast.info('您的注册理由正在审批中')
|
||||||
|
if (redirect) redirect()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.error('登录失败')
|
toast.error('登录失败')
|
||||||
|
|||||||
@@ -185,10 +185,11 @@
|
|||||||
<NotificationContainer :item="item" :markRead="markRead">
|
<NotificationContainer :item="item" :markRead="markRead">
|
||||||
{{ item.fromUser.username }} 希望注册为会员,理由是:{{ item.content }}
|
{{ item.fromUser.username }} 希望注册为会员,理由是:{{ item.content }}
|
||||||
<template #actions v-if="authState.role === 'ADMIN'">
|
<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-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 class="mark-reject-button-item" @click="reject(item.fromUser.id, item.id)">拒绝</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="mark-read-button-item" @click="markRead(item.id)">已读</div>
|
||||||
</template>
|
</template>
|
||||||
</NotificationContainer>
|
</NotificationContainer>
|
||||||
</template>
|
</template>
|
||||||
@@ -269,10 +270,14 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const markAllRead = async () => {
|
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) {
|
if (ok) {
|
||||||
notifications.value.forEach(n => n.read = true)
|
notifications.value.forEach(n => {
|
||||||
toast.success('已读所有消息')
|
if (n.type !== 'REGISTER_REQUEST') n.read = true
|
||||||
|
})
|
||||||
|
toast.success('已读所有消息(注册请求除外)')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,12 +48,14 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.isGoogle) {
|
if (this.isGoogle) {
|
||||||
|
this.isWaitingForRegister = true
|
||||||
const token = this.googleToken || sessionStorage.getItem('google_id_token')
|
const token = this.googleToken || sessionStorage.getItem('google_id_token')
|
||||||
if (!token) {
|
if (!token) {
|
||||||
toast.error('Google 登录失败')
|
toast.error('Google 登录失败')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await googleAuthWithToken(token, this.reason, () => { this.$router.push('/') })
|
await googleAuthWithToken(token, this.reason, () => { this.$router.push('/') })
|
||||||
|
this.isWaitingForRegister = false
|
||||||
sessionStorage.removeItem('google_id_token')
|
sessionStorage.removeItem('google_id_token')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class SecurityConfig {
|
|||||||
CorsConfiguration cfg = new CorsConfiguration();
|
CorsConfiguration cfg = new CorsConfiguration();
|
||||||
cfg.setAllowedOrigins(List.of(
|
cfg.setAllowedOrigins(List.of(
|
||||||
"http://127.0.0.1:8080", // 前端调试地址
|
"http://127.0.0.1:8080", // 前端调试地址
|
||||||
|
"http://localhost:8080", // 前端调试地址
|
||||||
// "http://129.204.254.110", // 前端调试地址
|
// "http://129.204.254.110", // 前端调试地址
|
||||||
"https://www.open-isle.com", // 生产域名
|
"https://www.open-isle.com", // 生产域名
|
||||||
"689d7858-openisle.cjt807916.workers.dev" // cloudflare 部署域名
|
"689d7858-openisle.cjt807916.workers.dev" // cloudflare 部署域名
|
||||||
|
|||||||
@@ -97,11 +97,24 @@ public class AuthController {
|
|||||||
Optional<User> user = googleAuthService.authenticate(req.getIdToken(), req.getReason(), registerModeService.getRegisterMode());
|
Optional<User> user = googleAuthService.authenticate(req.getIdToken(), req.getReason(), registerModeService.getRegisterMode());
|
||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
if (!user.get().isApproved()) {
|
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.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")
|
@GetMapping("/check")
|
||||||
|
|||||||
Reference in New Issue
Block a user