From 063435a58454ad76c8e09eed8659c19be8519ff8 Mon Sep 17 00:00:00 2001 From: walker Date: Mon, 5 Jun 2023 10:40:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E7=99=BB=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/UserApi.ts | 22 +++++---- src/pages/UserLogin.vue | 6 +-- src/pages/UserRegister.vue | 94 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 src/pages/UserRegister.vue diff --git a/src/api/UserApi.ts b/src/api/UserApi.ts index d2e129d..41f3cf0 100644 --- a/src/api/UserApi.ts +++ b/src/api/UserApi.ts @@ -18,13 +18,22 @@ interface User { registerTime: string; } +const PasswordSult = '4a6d74126bfd06d69406fcccb7e7d5d9'; // 密码加盐 +function encryptPassword(password: string): string { + const md5 = new Md5(); + return md5.appendStr(`${password}${PasswordSult}`).end() as string; +} + /** * 用户注册 * @param info * @returns */ export async function register(info: RegisterInfo): Promise { - const response = await api.post(`${UserUriBase}/register`, info); + const response = await api.post(`${UserUriBase}/register`, { + ...info, + password: encryptPassword(info.password), + }); return response.data as User; } @@ -33,21 +42,14 @@ interface LoginInfo { password: string; } -const PasswordSult = 'sdfs'; - /** * 用户登录 * @param loginInfo * @returns */ export async function login(loginInfo: LoginInfo): Promise { - const md5 = new Md5(); - const encryptedPassword = md5 - .appendStr(`${loginInfo.password}${PasswordSult}`) - .end(); - const info = { ...loginInfo, password: encryptedPassword }; - console.log(info); - const response = await api.post(`${UserUriBase}/login`, loginInfo); + const info = { ...loginInfo, password: encryptPassword(loginInfo.password) }; + const response = await api.post(`${UserUriBase}/login`, info); return response.data; } diff --git a/src/pages/UserLogin.vue b/src/pages/UserLogin.vue index 558f1e6..ee9fdf1 100644 --- a/src/pages/UserLogin.vue +++ b/src/pages/UserLogin.vue @@ -38,7 +38,7 @@
- +
@@ -57,6 +57,7 @@ import { reactive } from 'vue'; import { useRouter } from 'vue-router'; const $q = useQuasar(); +const router = useRouter(); const loginInfo = reactive({ account: '', @@ -64,11 +65,10 @@ const loginInfo = reactive({ }); async function doLogin() { - console.log(loginInfo); try { const token = await login(loginInfo); saveJwtToken(token); - useRouter().push({ name: 'home' }); + router.push({ name: 'home' }); } catch (err) { const apiErr = err as ApiError; $q.notify({ diff --git a/src/pages/UserRegister.vue b/src/pages/UserRegister.vue new file mode 100644 index 0000000..a2f3853 --- /dev/null +++ b/src/pages/UserRegister.vue @@ -0,0 +1,94 @@ + + + + +