diff --git a/open-isle-cli/src/utils/github.js b/open-isle-cli/src/utils/github.js index 9b2e4bc78..82dcfab46 100644 --- a/open-isle-cli/src/utils/github.js +++ b/open-isle-cli/src/utils/github.js @@ -23,19 +23,37 @@ export async function githubExchange(code, state, reason) { setToken(data.token) await loadCurrentUser() toast.success('登录成功') - return true + return { + success: true, + needReason: false + } } else if (data.reason_code === 'NOT_APPROVED') { toast.info('当前为注册审核模式,请填写注册理由') - sessionStorage.setItem('github_code', code) - return 'NEED_REASON' + return { + success: false, + needReason: true, + token: data.token + } } else if (data.reason_code === 'IS_APPROVING') { toast.info('您的注册理由正在审批中') - return true + return { + success: true, + needReason: false + } } else { toast.error(data.error || '登录失败') + return { + success: false, + needReason: false, + error: data.error || '登录失败' + } } } catch (e) { toast.error('登录失败') + return { + success: false, + needReason: false, + error: '登录失败' + } } - return false } diff --git a/open-isle-cli/src/utils/google.js b/open-isle-cli/src/utils/google.js index 53840b734..183c838e5 100644 --- a/open-isle-cli/src/utils/google.js +++ b/open-isle-cli/src/utils/google.js @@ -17,12 +17,12 @@ export async function googleGetIdToken() { }) } -export async function googleAuthWithToken(idToken, reason, redirect_success, redirect_not_approved) { +export async function googleAuthWithToken(idToken, redirect_success, redirect_not_approved) { try { const res = await fetch(`${API_BASE_URL}/api/auth/google`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ idToken, reason }) + body: JSON.stringify({ idToken }) }) const data = await res.json() if (res.ok && data.token) { @@ -32,8 +32,7 @@ export async function googleAuthWithToken(idToken, reason, redirect_success, red if (redirect_success) redirect_success() } else if (data.reason_code === 'NOT_APPROVED') { toast.info('当前为注册审核模式,请填写注册理由') - sessionStorage.setItem('google_id_token', idToken) - if (redirect_not_approved) redirect_not_approved() + if (redirect_not_approved) redirect_not_approved(data.token) } else if (data.reason_code === 'IS_APPROVING') { toast.info('您的注册理由正在审批中') if (redirect_success) redirect_success() @@ -46,7 +45,7 @@ export async function googleAuthWithToken(idToken, reason, redirect_success, red export async function googleSignIn(redirect_success, redirect_not_approved) { try { const token = await googleGetIdToken() - await googleAuthWithToken(token, '', redirect_success, redirect_not_approved) + await googleAuthWithToken(token, redirect_success, redirect_not_approved) } catch { /* ignore */ } diff --git a/open-isle-cli/src/views/GithubCallbackPageView.vue b/open-isle-cli/src/views/GithubCallbackPageView.vue index c8d285698..0a191ffbc 100644 --- a/open-isle-cli/src/views/GithubCallbackPageView.vue +++ b/open-isle-cli/src/views/GithubCallbackPageView.vue @@ -12,8 +12,9 @@ export default { const code = url.searchParams.get('code') const state = url.searchParams.get('state') const result = await githubExchange(code, state, '') - if (result === 'NEED_REASON') { - this.$router.push('/signup-reason?github=1') + + if (result.needReason) { + this.$router.push('/signup-reason?token=' + result.token) } else { this.$router.push('/') } diff --git a/open-isle-cli/src/views/LoginPageView.vue b/open-isle-cli/src/views/LoginPageView.vue index 0ee6d3cb1..39611de0b 100644 --- a/open-isle-cli/src/views/LoginPageView.vue +++ b/open-isle-cli/src/views/LoginPageView.vue @@ -75,7 +75,6 @@ export default { toast.success('登录成功') this.$router.push('/') } else if (data.reason_code === 'NOT_VERIFIED') { - sessionStorage.setItem('signup_username', data.username) toast.info('当前邮箱未验证,已经为您重新发送验证码') this.$router.push({ path: '/signup', query: { verify: 1, u: this.username } }) } else if (data.reason_code === 'NOT_APPROVED') { @@ -89,11 +88,14 @@ export default { } }, loginWithGoogle() { - googleSignIn(() => { - this.$router.push('/') - }, () => { - this.$router.push('/signup-reason?google=1') - }) + googleSignIn( + () => { + this.$router.push('/') + }, + (token) => { + this.$router.push('/signup-reason?token=' + token) + } + ) }, loginWithGithub() { githubAuthorize() diff --git a/open-isle-cli/src/views/SignupPageView.vue b/open-isle-cli/src/views/SignupPageView.vue index 84f3d6598..35ae1f9bd 100644 --- a/open-isle-cli/src/views/SignupPageView.vue +++ b/open-isle-cli/src/views/SignupPageView.vue @@ -86,7 +86,7 @@