mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat(i18n): add localized content for authentication error
This commit is contained in:
1 parent
bd1d5af699
commit
013a5acaa7
5 files changed
+46
-15
No files matched your search
@@ -55,5 +55,15 @@
|
|||||||
"not_registered": "Don't have an account?",
|
"not_registered": "Don't have an account?",
|
||||||
"continue_as_guest": "Continue as Guest",
|
"continue_as_guest": "Continue as Guest",
|
||||||
"password_rules": "At least 8 characters, including uppercase and lowercase letters and numbers"
|
"password_rules": "At least 8 characters, including uppercase and lowercase letters and numbers"
|
||||||
|
},
|
||||||
|
"authform_error": {
|
||||||
|
"too_many_requests": "Too many requests, please try again in 2 minutes",
|
||||||
|
"unauthorized": "Invalid username or password",
|
||||||
|
"auth_failed": "Something went wrong",
|
||||||
|
"invalid_username": "Invalid username",
|
||||||
|
"invalid_email": "Invalid email",
|
||||||
|
"invalid_password": "Invalid password",
|
||||||
|
"username_taken": "Username is already taken",
|
||||||
|
"email_taken": "Email is already taken"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,5 +55,15 @@
|
|||||||
"not_registered": "還沒有帳號嗎?",
|
"not_registered": "還沒有帳號嗎?",
|
||||||
"continue_as_guest": "以訪客身分繼續",
|
"continue_as_guest": "以訪客身分繼續",
|
||||||
"password_rules": "至少 8 個字元,包含數字及大小寫字母"
|
"password_rules": "至少 8 個字元,包含數字及大小寫字母"
|
||||||
|
},
|
||||||
|
"authform_error": {
|
||||||
|
"too_many_requests": "太多請求,兩分鐘後再試一次",
|
||||||
|
"unauthorized": "無效的帳號名稱或密碼",
|
||||||
|
"auth_failed": "出了點問題",
|
||||||
|
"invalid_username": "無效的帳號名稱",
|
||||||
|
"invalid_email": "無效的電子郵件",
|
||||||
|
"invalid_password": "無效的密碼",
|
||||||
|
"username_taken": "帳號名稱已被使用",
|
||||||
|
"email_taken": "電子郵件已被使用"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import api from './api'
|
import api from './api'
|
||||||
|
import { i18n } from '../i18n'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TooManyRequestsError,
|
TooManyRequestsError,
|
||||||
@@ -32,11 +33,15 @@ function handleRequestError(err: {
|
|||||||
const { path, msg } = errors[0]
|
const { path, msg } = errors[0]
|
||||||
switch (path) {
|
switch (path) {
|
||||||
case 'username':
|
case 'username':
|
||||||
throw new ValidationError('Username is already taken')
|
throw new ValidationError(
|
||||||
|
i18n.global.t('authform_error.username_taken')
|
||||||
|
)
|
||||||
case 'email':
|
case 'email':
|
||||||
throw new ValidationError('Email is already taken')
|
throw new ValidationError(i18n.global.t('authform_error.email_taken'))
|
||||||
case 'password':
|
case 'password':
|
||||||
throw new ValidationError('Password is too weak')
|
throw new ValidationError(
|
||||||
|
i18n.global.t('authform_error.invalid_password')
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
throw new ValidationError(msg)
|
throw new ValidationError(msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
import AuthForm from '../components/AuthForm.vue'
|
import AuthForm from '../components/AuthForm.vue'
|
||||||
import DynamicBackground from '../components/DynamicBackground.vue'
|
import DynamicBackground from '../components/DynamicBackground.vue'
|
||||||
import HeaderPart from '../components/header/HeaderPart.vue'
|
import HeaderPart from '../components/header/HeaderPart.vue'
|
||||||
@@ -10,6 +11,8 @@ import {
|
|||||||
} from '../utils/errors'
|
} from '../utils/errors'
|
||||||
import { login } from '../utils/auth'
|
import { login } from '../utils/auth'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
const handleLogin = async ({
|
const handleLogin = async ({
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
@@ -27,19 +30,19 @@ const handleLogin = async ({
|
|||||||
if (isSuccess) success()
|
if (isSuccess) success()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof TooManyRequestsError) {
|
if (err instanceof TooManyRequestsError) {
|
||||||
error('太多請求,兩分鐘後再試一次。')
|
error(t('authform_error.too_many_requests'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (err instanceof UnauthorizedError) {
|
if (err instanceof UnauthorizedError) {
|
||||||
error('錯誤的帳號名稱或密碼。')
|
error(t('authform_error.unauthorized'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (err instanceof ValidationError) {
|
if (err instanceof ValidationError) {
|
||||||
error('無效的帳號名稱或密碼。')
|
error(err.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.error(err)
|
console.error(err)
|
||||||
error('出了點問題。')
|
error(t('authform_error.auth_failed'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { isValidUsername } from '../../../packages/utils'
|
import { isValidUsername } from '../../../packages/utils'
|
||||||
import { passwordPolicy } from '../../../packages/constants'
|
import { passwordPolicy } from '../../../packages/constants'
|
||||||
@@ -12,6 +13,8 @@ import {
|
|||||||
ValidationError,
|
ValidationError,
|
||||||
} from '../utils/errors'
|
} from '../utils/errors'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
function handleRegister({
|
function handleRegister({
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
@@ -30,11 +33,11 @@ function handleRegister({
|
|||||||
.then(success)
|
.then(success)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err instanceof TooManyRequestsError) {
|
if (err instanceof TooManyRequestsError) {
|
||||||
error('太多請求,兩分鐘後再試一次。')
|
error(t('authform_error.too_many_requests'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (err instanceof UnauthorizedError) {
|
if (err instanceof UnauthorizedError) {
|
||||||
error('無效的帳號名稱或密碼。')
|
error(t('authform_error.unauthorized'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (err instanceof ValidationError) {
|
if (err instanceof ValidationError) {
|
||||||
@@ -42,7 +45,7 @@ function handleRegister({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.error(err)
|
console.error(err)
|
||||||
error('出了點問題。')
|
error(t('authform_error.auth_failed'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,15 +62,15 @@ async function check({
|
|||||||
error: (msg: string) => void
|
error: (msg: string) => void
|
||||||
}) {
|
}) {
|
||||||
if (username && !isValidUsername(username)) {
|
if (username && !isValidUsername(username)) {
|
||||||
error('無效的帳號名稱')
|
error(t('authform_error.invalid_username'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (email && !validator.isEmail(email)) {
|
if (email && !validator.isEmail(email)) {
|
||||||
error('無效的電子郵件')
|
error(t('authform_error.invalid_email'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (password && !validator.isStrongPassword(password, passwordPolicy)) {
|
if (password && !validator.isStrongPassword(password, passwordPolicy)) {
|
||||||
error('密碼必須超過8個字元,至少包含一個數字、一個大寫及一個小寫。')
|
error(t('authform_error.invalid_password'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -78,11 +81,11 @@ async function check({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (err instanceof TooManyRequestsError) {
|
if (err instanceof TooManyRequestsError) {
|
||||||
error('太多請求,兩分鐘後再試一次。')
|
error(t('authform_error.too_many_requests'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.error(err)
|
console.error(err)
|
||||||
error('出了點問題。')
|
error(t('authform_error.registration_failed'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user