diff --git a/open-isle-cli/src/utils/google.js b/open-isle-cli/src/utils/google.js index 3dd1cd6d5..ba0d531ae 100644 --- a/open-isle-cli/src/utils/google.js +++ b/open-isle-cli/src/utils/google.js @@ -16,7 +16,7 @@ export async function googleGetIdToken() { }) } -export async function googleAuthWithToken(idToken, reason, redirect) { +export async function googleAuthWithToken(idToken, reason, redirect_success, redirect_not_approved) { try { const res = await fetch(`${API_BASE_URL}/api/auth/google`, { method: 'POST', @@ -28,20 +28,24 @@ export async function googleAuthWithToken(idToken, reason, redirect) { setToken(data.token) await loadCurrentUser() toast.success('登录成功') - if (redirect) redirect() + if (redirect_success) redirect_success() } else if (data.reason_code === 'NOT_APPROVED') { - toast.info('您的注册理由正在审批中') - if (redirect) redirect() + toast.info('当前为注册审核模式,请填写注册理由') + sessionStorage.setItem('google_id_token', idToken) + if (redirect_not_approved) redirect_not_approved() + } else if (data.reason_code === 'IS_APPROVING') { + toast.info('您的注册理由正在审批中') + if (redirect_success) redirect_success() } } catch (e) { toast.error('登录失败') } } -export async function googleSignIn(redirect, reason) { +export async function googleSignIn(redirect_success, redirect_not_approved) { try { const token = await googleGetIdToken() - await googleAuthWithToken(token, reason, redirect) + await googleAuthWithToken(token, '', redirect_success, redirect_not_approved) } catch { /* ignore */ } diff --git a/open-isle-cli/src/views/LoginPageView.vue b/open-isle-cli/src/views/LoginPageView.vue index 7cca7d2ee..66392e83d 100644 --- a/open-isle-cli/src/views/LoginPageView.vue +++ b/open-isle-cli/src/views/LoginPageView.vue @@ -88,6 +88,8 @@ export default { loginWithGoogle() { googleSignIn(() => { this.$router.push('/') + }, () => { + this.$router.push('/signup-reason?google=1') }) } } diff --git a/open-isle-cli/src/views/SignupPageView.vue b/open-isle-cli/src/views/SignupPageView.vue index 50ceaf497..19d426106 100644 --- a/open-isle-cli/src/views/SignupPageView.vue +++ b/open-isle-cli/src/views/SignupPageView.vue @@ -204,6 +204,8 @@ export default { } else { googleSignIn(() => { this.$router.push('/') + }, () => { + this.$router.push('/signup-reason') }) } } diff --git a/open-isle-cli/src/views/SignupReasonPageView.vue b/open-isle-cli/src/views/SignupReasonPageView.vue index 7faf4454f..d1c0d1a01 100644 --- a/open-isle-cli/src/views/SignupReasonPageView.vue +++ b/open-isle-cli/src/views/SignupReasonPageView.vue @@ -54,7 +54,10 @@ export default { toast.error('Google 登录失败') return } - await googleAuthWithToken(token, this.reason, () => { this.$router.push('/') }) + await googleAuthWithToken(token, this.reason, + () => { this.$router.push('/') }, + () => { this.error = 'Google 登录失败' } + ) this.isWaitingForRegister = false sessionStorage.removeItem('google_id_token') return @@ -138,5 +141,4 @@ export default { .signup-page-button-primary.disabled:hover { cursor: not-allowed; } - diff --git a/src/main/java/com/openisle/controller/AuthController.java b/src/main/java/com/openisle/controller/AuthController.java index ae1e62a44..52895c21d 100644 --- a/src/main/java/com/openisle/controller/AuthController.java +++ b/src/main/java/com/openisle/controller/AuthController.java @@ -93,9 +93,14 @@ public class AuthController { Optional user = googleAuthService.authenticate(req.getIdToken(), req.getReason(), registerModeService.getRegisterMode()); if (user.isPresent()) { if (!user.get().isApproved()) { - if (req.getReason() != null && !req.getReason().isEmpty()) { - // do not send empty notification (while try login) + if (user.get().getRegisterReason() != null && !user.get().getRegisterReason().isEmpty()) { + // do not send empty notifition (while try login) notificationService.createRegisterRequestNotifications(user.get(), req.getReason()); + + return ResponseEntity.badRequest().body(Map.of( + "error", "Account awaiting approval", + "reason_code", "IS_APPROVING" + )); } return ResponseEntity.badRequest().body(Map.of( "error", "Account awaiting approval", diff --git a/src/main/java/com/openisle/service/GoogleAuthService.java b/src/main/java/com/openisle/service/GoogleAuthService.java index 0cdf80953..aaa0b3145 100644 --- a/src/main/java/com/openisle/service/GoogleAuthService.java +++ b/src/main/java/com/openisle/service/GoogleAuthService.java @@ -50,6 +50,12 @@ public class GoogleAuthService { user.setVerificationCode(null); userRepository.save(user); } + + if (!user.isApproved() && reason != null && !reason.isEmpty()) { + user.setRegisterReason(reason); + userRepository.save(user); + } + return user; } User user = new User();