mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
83 lines
1.9 KiB
Vue
83 lines
1.9 KiB
Vue
<script setup lang="ts">
|
|
import { isValidUsername } from '../../../packages/utils'
|
|
import AuthForm from '../components/AuthForm.vue'
|
|
import DynamicBackground from '../components/DynamicBackground.vue'
|
|
import HeaderPart from '../components/header/HeaderPart.vue'
|
|
import { TooManyRequestsError, ValidationError } from '../utils/errors'
|
|
import { checkUsername, chooseUsername } from '../utils/auth'
|
|
|
|
async function check({
|
|
username,
|
|
error,
|
|
}: {
|
|
username: string
|
|
// eslint-disable-next-line no-unused-vars
|
|
error: (msg: string) => void
|
|
}) {
|
|
if (username) {
|
|
if (!isValidUsername(username)) {
|
|
error('無效的帳號名稱')
|
|
return
|
|
}
|
|
try {
|
|
await checkUsername(username)
|
|
} catch (err) {
|
|
if (err instanceof TooManyRequestsError) {
|
|
error('太多請求,兩分鐘後再試一次。')
|
|
return
|
|
}
|
|
if (err instanceof ValidationError) {
|
|
error(err.message)
|
|
return
|
|
}
|
|
error('出了點問題,請再試一次。')
|
|
}
|
|
}
|
|
}
|
|
|
|
async function handleSubmit({
|
|
username,
|
|
success,
|
|
error,
|
|
}: {
|
|
username: string
|
|
success: () => void
|
|
// eslint-disable-next-line no-unused-vars
|
|
error: (msg: string) => void
|
|
}) {
|
|
try {
|
|
await chooseUsername(username)
|
|
success()
|
|
} catch (err: any) {
|
|
if (err instanceof TooManyRequestsError) {
|
|
error('太多請求,兩分鐘後再試一次。')
|
|
return
|
|
}
|
|
if (err instanceof ValidationError) {
|
|
error(err.message)
|
|
return
|
|
}
|
|
error(err.message)
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="w-screen h-screen">
|
|
<DynamicBackground class="w-full h-full" />
|
|
<div
|
|
class="h-screen w-screen absolute top-0 left-0 flex flex-wrap justify-center content-center"
|
|
>
|
|
<HeaderPart />
|
|
<div class="w-fit">
|
|
<AuthForm
|
|
@onSubmit="handleSubmit"
|
|
@onChange="check"
|
|
type="username"
|
|
:socialLogin="false"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|