diff --git a/package-lock.json b/package-lock.json
index c47a8f0..67e8334 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,7 +8,6 @@
"name": "surl-front",
"version": "0.0.0",
"dependencies": {
- "ky": "^1.5.0",
"pinia": "^2.2.0",
"vite-plugin-vuetify": "^2.0.3",
"vue": "^3.4.31",
@@ -891,17 +890,6 @@
"he": "bin/he"
}
},
- "node_modules/ky": {
- "version": "1.5.0",
- "resolved": "https://registry.npmmirror.com/ky/-/ky-1.5.0.tgz",
- "integrity": "sha512-bkQo+UqryW6Zmo/DsixYZE4Z9t2mzvNMhceyIhuMuInb3knm5Q+GNGMKveydJAj+Z6piN1SwI6eR/V0G+Z0BtA==",
- "engines": {
- "node": ">=18"
- },
- "funding": {
- "url": "https://github.com/sindresorhus/ky?sponsor=1"
- }
- },
"node_modules/magic-string": {
"version": "0.30.10",
"resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.10.tgz",
diff --git a/package.json b/package.json
index 8e46510..0eb9711 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,6 @@
"preview": "vite preview"
},
"dependencies": {
- "ky": "^1.5.0",
"pinia": "^2.2.0",
"vite-plugin-vuetify": "^2.0.3",
"vue": "^3.4.31",
diff --git a/src/components/items/RegisterDialog.vue b/src/components/items/RegisterDialog.vue
new file mode 100644
index 0000000..e944925
--- /dev/null
+++ b/src/components/items/RegisterDialog.vue
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+ {{ registerFailedNote }}
+
+
+
+ {{ t('$vuetify.login.agreement') }}
+ {{ t('$vuetify.login.termsOfService') }}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/views/HomeView.vue b/src/components/views/HomeView.vue
index f359c2f..ecedb9a 100644
--- a/src/components/views/HomeView.vue
+++ b/src/components/views/HomeView.vue
@@ -3,6 +3,7 @@ import {ref} from "vue";
import {login, logout} from "../../script/functions";
import {useUserinfoStore} from "../../stores/userinfo-store.ts";
import {useLocale, useTheme} from "vuetify";
+import RegisterDialog from "../items/RegisterDialog.vue";
const {t, current} = useLocale()
const theme = useTheme()
@@ -14,11 +15,12 @@ const passwordVisibleState = ref(false)
const loading = ref(false)
const loginDisabled = ref(false)
const loginIcon = ref(null)
-const isLoginFaild = ref(false)
+const isLoginFailed = ref(false)
+const showRegisterDialog = ref(false)
async function tryLogin() {
loading.value = true
- isLoginFaild.value = false
+ isLoginFailed.value = false
const isSuccess = await login(username.value, password.value)
if (isSuccess) {
loginIcon.value = "mdi-check"
@@ -30,16 +32,16 @@ async function tryLogin() {
loginIcon.value = null
}, 1500)
} else {
- isLoginFaild.value = true
+ isLoginFailed.value = true
loading.value = false
}
}
function resetLoginError() {
- isLoginFaild.value = false
+ isLoginFailed.value = false
}
-function toogleLocale() {
+function toggleLocale() {
switch (current.value) {
case 'en':
current.value = 'zhHans';
@@ -76,14 +78,15 @@ function toggleTheme() {
flat hide-details single-line append-inner-icon="mdi-magnify">
-
+
-
{{ t('$vuetify.user.login') }}
@@ -91,6 +94,10 @@ function toggleTheme() {
append-icon="mdi-logout">
{{ t('$vuetify.user.logout') }}
+
+ {{ t('$vuetify.user.register') }}
+
@@ -105,20 +112,20 @@ function toggleTheme() {
-
+
-
-
- {{ t('$vuetify.login.failedNote') }}
+
+ {{ t('$vuetify.login.failedNote') }}
@@ -128,10 +135,9 @@ function toggleTheme() {
-
-
+
\ No newline at end of file
diff --git a/src/script/functions.ts b/src/script/functions.ts
index 855f22f..3c51269 100644
--- a/src/script/functions.ts
+++ b/src/script/functions.ts
@@ -54,6 +54,24 @@ async function login(username: string, password: string): Promise {
}
}
+async function register(username: string, password: string): Promise {
+ const responsePromise = request('reg', {
+ method: 'POST',
+ body: JSON.stringify({username, password}),
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ mode: 'cors'
+ })
+ try {
+ const response = await responsePromise
+ const body: Msg = await response.json()
+ return body.code == 0
+ } catch (_) {
+ return false
+ }
+}
+
function logout() {
const userinfoStore = useUserinfoStore()
userinfoStore.setToken('')
@@ -64,12 +82,12 @@ async function checkLogin(): Promise {
const userinfoStore = useUserinfoStore()
if (userinfoStore.isLogin) {
try {
- const reponse = await request('loginCheck', {
+ const response = await request('loginCheck', {
headers: {
'Authorization': `Bearer ${userinfoStore.token}`
}
})
- const body: Msg = await reponse.json()
+ const body: Msg = await response.json()
return body.code == 0
} catch (_) {
return false
@@ -79,4 +97,4 @@ async function checkLogin(): Promise {
}
}
-export {request, login, logout, checkLogin}
\ No newline at end of file
+export {request, login, logout, checkLogin, register}
\ No newline at end of file
diff --git a/src/script/i18n/en.ts b/src/script/i18n/en.ts
index bce416a..fb0e6f4 100644
--- a/src/script/i18n/en.ts
+++ b/src/script/i18n/en.ts
@@ -12,7 +12,8 @@ const en: LocaleInterface = {
},
user: {
login: 'Login',
- logout: 'Logout'
+ logout: 'Logout',
+ register: 'Register'
},
login: {
title: 'Login',
@@ -26,6 +27,23 @@ const en: LocaleInterface = {
login: 'LOGIN',
cancel: 'CANCEL'
}
+ },
+ register: {
+ title: "REGISTER",
+ username: "USERNAME",
+ password: "PASSWORD",
+ confirmPassword: "CONFIRM PASSWORD",
+ usernameInvalidNote: "Invalid username format",
+ passwordInvalidNote: "Invalid password format",
+ passwordConfirmInvalidNote: "Password confirmation does not match the password",
+ failedNote: "Register failed",
+ rememberMe: "string",
+ agreement: "string",
+ termsOfService: "string",
+ button: {
+ register: "string",
+ cancel: "string"
+ }
}
}
export default en
\ No newline at end of file
diff --git a/src/script/i18n/locale-interface.ts b/src/script/i18n/locale-interface.ts
index 37c7dfc..f04d377 100644
--- a/src/script/i18n/locale-interface.ts
+++ b/src/script/i18n/locale-interface.ts
@@ -9,7 +9,8 @@ export default interface LocaleInterface {
},
user: {
login: string,
- logout: string
+ logout: string,
+ register: string
},
login: {
title: string,
@@ -24,6 +25,23 @@ export default interface LocaleInterface {
cancel: string
}
},
+ register: {
+ title: string,
+ username: string,
+ password: string,
+ confirmPassword: string,
+ usernameInvalidNote: string,
+ passwordInvalidNote: string,
+ passwordConfirmInvalidNote: string,
+ failedNote: string,
+ rememberMe: string,
+ agreement: string,
+ termsOfService: string,
+ button: {
+ register: string,
+ cancel: string
+ }
+ }
// ==================
// vuetify
// ==================
diff --git a/src/script/i18n/zhHans.ts b/src/script/i18n/zhHans.ts
index b7b9816..e7bd080 100644
--- a/src/script/i18n/zhHans.ts
+++ b/src/script/i18n/zhHans.ts
@@ -12,7 +12,8 @@ const zhHans: LocaleInterface = {
},
user: {
login: '登录',
- logout: '退出'
+ logout: '退出',
+ register: '注册',
},
login: {
title: '登录',
@@ -26,6 +27,23 @@ const zhHans: LocaleInterface = {
login: '登录',
cancel: '取消'
}
+ },
+ register: {
+ title: "注册",
+ username: "用户名,大小写字母和数字,4-16位",
+ password: "密码,大小写字母、数字、下划线,8-16位",
+ confirmPassword: "确认密码",
+ usernameInvalidNote: "用户名不符合规则",
+ passwordInvalidNote: "密码不符合规则",
+ passwordConfirmInvalidNote: "两次输入的密码不一致",
+ failedNote: "注册失败, 用户名重复或网络异常",
+ rememberMe: "string",
+ agreement: "string",
+ termsOfService: "string",
+ button: {
+ register: "注册",
+ cancel: "取消"
+ }
}
}
export default zhHans
\ No newline at end of file