mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-21 14:30:59 +08:00
Compare commits
1 Commits
codex/fix-
...
codex/add-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0df78deee |
@@ -7,4 +7,5 @@ import lombok.Data;
|
|||||||
public class DiscordLoginRequest {
|
public class DiscordLoginRequest {
|
||||||
private String code;
|
private String code;
|
||||||
private String redirectUri;
|
private String redirectUri;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ import lombok.Data;
|
|||||||
public class GithubLoginRequest {
|
public class GithubLoginRequest {
|
||||||
private String code;
|
private String code;
|
||||||
private String redirectUri;
|
private String redirectUri;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class GoogleLoginRequest {
|
public class GoogleLoginRequest {
|
||||||
private String idToken;
|
private String idToken;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ import lombok.Data;
|
|||||||
public class MakeReasonRequest {
|
public class MakeReasonRequest {
|
||||||
private String token;
|
private String token;
|
||||||
private String reason;
|
private String reason;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ public class RegisterRequest {
|
|||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
private String captcha;
|
private String captcha;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ public class TwitterLoginRequest {
|
|||||||
private String code;
|
private String code;
|
||||||
private String redirectUri;
|
private String redirectUri;
|
||||||
private String codeVerifier;
|
private String codeVerifier;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ import lombok.Data;
|
|||||||
public class VerifyRequest {
|
public class VerifyRequest {
|
||||||
private String username;
|
private String username;
|
||||||
private String code;
|
private String code;
|
||||||
|
private String inviteToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ import { discordExchange } from '~/utils/discord'
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
const code = url.searchParams.get('code')
|
const code = url.searchParams.get('code')
|
||||||
const state = url.searchParams.get('state')
|
const inviteToken = url.searchParams.get('state')
|
||||||
const result = await discordExchange(code, state, '')
|
const result = await discordExchange(code, inviteToken, '')
|
||||||
|
|
||||||
if (result.needReason) {
|
if (result.needReason) {
|
||||||
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
|
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
|
||||||
|
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
|
||||||
} else {
|
} else {
|
||||||
navigateTo('/', { replace: true })
|
navigateTo('/', { replace: true })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ import { githubExchange } from '~/utils/github'
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
const code = url.searchParams.get('code')
|
const code = url.searchParams.get('code')
|
||||||
const state = url.searchParams.get('state')
|
const inviteToken = url.searchParams.get('state')
|
||||||
const result = await githubExchange(code, state, '')
|
const result = await githubExchange(code, inviteToken, '')
|
||||||
|
|
||||||
if (result.needReason) {
|
if (result.needReason) {
|
||||||
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
|
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
|
||||||
|
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
|
||||||
} else {
|
} else {
|
||||||
navigateTo('/', { replace: true })
|
navigateTo('/', { replace: true })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,17 @@ import { googleAuthWithToken } from '~/utils/google'
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const hash = new URLSearchParams(window.location.hash.substring(1))
|
const hash = new URLSearchParams(window.location.hash.substring(1))
|
||||||
const idToken = hash.get('id_token')
|
const idToken = hash.get('id_token')
|
||||||
|
const inviteToken = hash.get('state')
|
||||||
if (idToken) {
|
if (idToken) {
|
||||||
await googleAuthWithToken(
|
await googleAuthWithToken(
|
||||||
idToken,
|
idToken,
|
||||||
|
inviteToken,
|
||||||
() => {
|
() => {
|
||||||
navigateTo('/', { replace: true })
|
navigateTo('/', { replace: true })
|
||||||
},
|
},
|
||||||
(token) => {
|
(token) => {
|
||||||
navigateTo(`/signup-reason?token=${token}`, { replace: true })
|
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
|
||||||
|
navigateTo(`/signup-reason?token=${token}${q}`, { replace: true })
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="other-login-page-content">
|
<div class="other-login-page-content">
|
||||||
<div class="login-page-button" @click="googleAuthorize">
|
<div class="login-page-button" @click="loginWithGoogle">
|
||||||
<img class="login-page-button-icon" src="../assets/icons/google.svg" alt="Google Logo" />
|
<img class="login-page-button-icon" src="../assets/icons/google.svg" alt="Google Logo" />
|
||||||
<div class="login-page-button-text">Google 登录</div>
|
<div class="login-page-button-text">Google 登录</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -115,6 +115,9 @@ const loginWithDiscord = () => {
|
|||||||
const loginWithTwitter = () => {
|
const loginWithTwitter = () => {
|
||||||
twitterAuthorize()
|
twitterAuthorize()
|
||||||
}
|
}
|
||||||
|
const loginWithGoogle = () => {
|
||||||
|
googleAuthorize()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -23,14 +23,17 @@ import BaseInput from '~/components/BaseInput.vue'
|
|||||||
import { toast } from '~/main'
|
import { toast } from '~/main'
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const reason = ref('')
|
const reason = ref('')
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
const isWaitingForRegister = ref(false)
|
const isWaitingForRegister = ref(false)
|
||||||
const token = ref('')
|
const token = ref('')
|
||||||
|
const inviteToken = ref('')
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
token.value = route.query.token || ''
|
token.value = route.query.token || ''
|
||||||
|
inviteToken.value = route.query.invite_token || ''
|
||||||
if (!token.value) {
|
if (!token.value) {
|
||||||
await navigateTo({ path: '/signup' }, { replace: true })
|
await navigateTo({ path: '/signup' }, { replace: true })
|
||||||
}
|
}
|
||||||
@@ -50,8 +53,9 @@ const submit = async () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
token: this.token,
|
token: token.value,
|
||||||
reason: this.reason,
|
reason: reason.value,
|
||||||
|
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
isWaitingForRegister.value = false
|
isWaitingForRegister.value = false
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="other-signup-page-content">
|
<div class="other-signup-page-content">
|
||||||
<div class="signup-page-button" @click="googleAuthorize">
|
<div class="signup-page-button" @click="signupWithGoogle">
|
||||||
<img class="signup-page-button-icon" src="~/assets/icons/google.svg" alt="Google Logo" />
|
<img class="signup-page-button-icon" src="~/assets/icons/google.svg" alt="Google Logo" />
|
||||||
<div class="signup-page-button-text">Google 注册</div>
|
<div class="signup-page-button-text">Google 注册</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -97,6 +97,7 @@ import { githubAuthorize } from '~/utils/github'
|
|||||||
import { googleAuthorize } from '~/utils/google'
|
import { googleAuthorize } from '~/utils/google'
|
||||||
import { twitterAuthorize } from '~/utils/twitter'
|
import { twitterAuthorize } from '~/utils/twitter'
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
|
const route = useRoute()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
const emailStep = ref(0)
|
const emailStep = ref(0)
|
||||||
const email = ref('')
|
const email = ref('')
|
||||||
@@ -109,9 +110,11 @@ const passwordError = ref('')
|
|||||||
const code = ref('')
|
const code = ref('')
|
||||||
const isWaitingForEmailSent = ref(false)
|
const isWaitingForEmailSent = ref(false)
|
||||||
const isWaitingForEmailVerified = ref(false)
|
const isWaitingForEmailVerified = ref(false)
|
||||||
|
const inviteToken = ref('')
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
username.value = route.query.u || ''
|
username.value = route.query.u || ''
|
||||||
|
inviteToken.value = route.query.invite_token || ''
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE_URL}/api/config`)
|
const res = await fetch(`${API_BASE_URL}/api/config`)
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -156,6 +159,7 @@ const sendVerification = async () => {
|
|||||||
username: username.value,
|
username: username.value,
|
||||||
email: email.value,
|
email: email.value,
|
||||||
password: password.value,
|
password: password.value,
|
||||||
|
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
isWaitingForEmailSent.value = false
|
isWaitingForEmailSent.value = false
|
||||||
@@ -184,12 +188,14 @@ const verifyCode = async () => {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
code: code.value,
|
code: code.value,
|
||||||
username: username.value,
|
username: username.value,
|
||||||
|
...(inviteToken.value ? { inviteToken: inviteToken.value } : {}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
if (registerMode.value === 'WHITELIST') {
|
if (registerMode.value === 'WHITELIST') {
|
||||||
navigateTo(`/signup-reason?token=${data.token}`, { replace: true })
|
const q = inviteToken.value ? `&invite_token=${inviteToken.value}` : ''
|
||||||
|
navigateTo(`/signup-reason?token=${data.token}${q}`, { replace: true })
|
||||||
} else {
|
} else {
|
||||||
toast.success('注册成功,请登录')
|
toast.success('注册成功,请登录')
|
||||||
navigateTo('/login', { replace: true })
|
navigateTo('/login', { replace: true })
|
||||||
@@ -203,14 +209,17 @@ const verifyCode = async () => {
|
|||||||
isWaitingForEmailVerified.value = false
|
isWaitingForEmailVerified.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const signupWithGoogle = () => {
|
||||||
|
googleAuthorize(inviteToken.value)
|
||||||
|
}
|
||||||
const signupWithGithub = () => {
|
const signupWithGithub = () => {
|
||||||
githubAuthorize()
|
githubAuthorize(inviteToken.value)
|
||||||
}
|
}
|
||||||
const signupWithDiscord = () => {
|
const signupWithDiscord = () => {
|
||||||
discordAuthorize()
|
discordAuthorize(inviteToken.value)
|
||||||
}
|
}
|
||||||
const signupWithTwitter = () => {
|
const signupWithTwitter = () => {
|
||||||
twitterAuthorize()
|
twitterAuthorize(inviteToken.value)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ import { twitterExchange } from '~/utils/twitter'
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
const code = url.searchParams.get('code')
|
const code = url.searchParams.get('code')
|
||||||
const state = url.searchParams.get('state')
|
const inviteToken = url.searchParams.get('state')
|
||||||
const result = await twitterExchange(code, state, '')
|
const result = await twitterExchange(code, inviteToken, '')
|
||||||
|
|
||||||
if (result.needReason) {
|
if (result.needReason) {
|
||||||
navigateTo(`/signup-reason?token=${result.token}`, { replace: true })
|
const q = inviteToken ? `&invite_token=${inviteToken}` : ''
|
||||||
|
navigateTo(`/signup-reason?token=${result.token}${q}`, { replace: true })
|
||||||
} else {
|
} else {
|
||||||
navigateTo('/', { replace: true })
|
navigateTo('/', { replace: true })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function discordAuthorize(state = '') {
|
|||||||
window.location.href = url
|
window.location.href = url
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function discordExchange(code, state, reason) {
|
export async function discordExchange(code, inviteToken, reason) {
|
||||||
try {
|
try {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -26,7 +26,7 @@ export async function discordExchange(code, state, reason) {
|
|||||||
code,
|
code,
|
||||||
redirectUri: `${window.location.origin}/discord-callback`,
|
redirectUri: `${window.location.origin}/discord-callback`,
|
||||||
reason,
|
reason,
|
||||||
state,
|
inviteToken,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function githubAuthorize(state = '') {
|
|||||||
window.location.href = url
|
window.location.href = url
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function githubExchange(code, state, reason) {
|
export async function githubExchange(code, inviteToken, reason) {
|
||||||
try {
|
try {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -26,7 +26,7 @@ export async function githubExchange(code, state, reason) {
|
|||||||
code,
|
code,
|
||||||
redirectUri: `${window.location.origin}/github-callback`,
|
redirectUri: `${window.location.origin}/github-callback`,
|
||||||
reason,
|
reason,
|
||||||
state,
|
inviteToken,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export async function googleGetIdToken() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function googleAuthorize() {
|
export function googleAuthorize(state = '') {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const GOOGLE_CLIENT_ID = config.public.googleClientId
|
const GOOGLE_CLIENT_ID = config.public.googleClientId
|
||||||
const WEBSITE_BASE_URL = config.public.websiteBaseUrl
|
const WEBSITE_BASE_URL = config.public.websiteBaseUrl
|
||||||
@@ -31,18 +31,23 @@ export function googleAuthorize() {
|
|||||||
}
|
}
|
||||||
const redirectUri = `${WEBSITE_BASE_URL}/google-callback`
|
const redirectUri = `${WEBSITE_BASE_URL}/google-callback`
|
||||||
const nonce = Math.random().toString(36).substring(2)
|
const nonce = Math.random().toString(36).substring(2)
|
||||||
const url = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=id_token&scope=openid%20email%20profile&nonce=${nonce}`
|
const url = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=id_token&scope=openid%20email%20profile&nonce=${nonce}&state=${state}`
|
||||||
window.location.href = url
|
window.location.href = url
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function googleAuthWithToken(idToken, redirect_success, redirect_not_approved) {
|
export async function googleAuthWithToken(
|
||||||
|
idToken,
|
||||||
|
inviteToken,
|
||||||
|
redirect_success,
|
||||||
|
redirect_not_approved,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
const res = await fetch(`${API_BASE_URL}/api/auth/google`, {
|
const res = await fetch(`${API_BASE_URL}/api/auth/google`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ idToken }),
|
body: JSON.stringify({ idToken, inviteToken }),
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
if (res.ok && data.token) {
|
if (res.ok && data.token) {
|
||||||
@@ -66,7 +71,7 @@ export async function googleAuthWithToken(idToken, redirect_success, redirect_no
|
|||||||
export async function googleSignIn(redirect_success, redirect_not_approved) {
|
export async function googleSignIn(redirect_success, redirect_not_approved) {
|
||||||
try {
|
try {
|
||||||
const token = await googleGetIdToken()
|
const token = await googleGetIdToken()
|
||||||
await googleAuthWithToken(token, redirect_success, redirect_not_approved)
|
await googleAuthWithToken(token, '', redirect_success, redirect_not_approved)
|
||||||
} catch {
|
} catch {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export async function twitterAuthorize(state = '') {
|
|||||||
window.location.href = url
|
window.location.href = url
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function twitterExchange(code, state, reason) {
|
export async function twitterExchange(code, inviteToken, reason) {
|
||||||
try {
|
try {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -55,7 +55,7 @@ export async function twitterExchange(code, state, reason) {
|
|||||||
code,
|
code,
|
||||||
redirectUri: `${window.location.origin}/twitter-callback`,
|
redirectUri: `${window.location.origin}/twitter-callback`,
|
||||||
reason,
|
reason,
|
||||||
state,
|
inviteToken,
|
||||||
codeVerifier,
|
codeVerifier,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user