From e15707460936afff009e2af39aee587843ad3a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Wed, 16 Oct 2024 23:53:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[*]=20=E6=94=B9=E7=94=A8=20v2=20=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/v2/email/email.api.ts | 13 +++++++++ src/api/v2/email/index.ts | 6 ++++- src/api/v2/email/password.api.ts | 12 +++++++++ src/api/v2/user/password.api.ts | 5 ++-- src/components/UserInfo.vue | 2 +- src/utils/request.js | 1 - src/views/auth/ResetPasswordView.vue | 40 ++++++++++++++++------------ 7 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 src/api/v2/email/email.api.ts create mode 100644 src/api/v2/email/password.api.ts diff --git a/src/api/v2/email/email.api.ts b/src/api/v2/email/email.api.ts new file mode 100644 index 0000000..c718901 --- /dev/null +++ b/src/api/v2/email/email.api.ts @@ -0,0 +1,13 @@ +//@ts-ignore +import { get } from '@/utils/request' +import base from '@/api/base' + +const email = async (username: string, email: string) => { + const rs = get(`${base.api_v2_url}/email/email`, { + username: username, + email: email + }) + return base.buildResponse(await rs) +} + +export default email diff --git a/src/api/v2/email/index.ts b/src/api/v2/email/index.ts index c96ca52..335fee4 100644 --- a/src/api/v2/email/index.ts +++ b/src/api/v2/email/index.ts @@ -1,5 +1,9 @@ import register from './register.api' +import password from './password.api' +import email from './email.api' export default { - register: register + register: register, + password: password, + email: email } diff --git a/src/api/v2/email/password.api.ts b/src/api/v2/email/password.api.ts new file mode 100644 index 0000000..1b122c5 --- /dev/null +++ b/src/api/v2/email/password.api.ts @@ -0,0 +1,12 @@ +//@ts-ignore +import { get } from '@/utils/request' +import base from '@/api/base' + +const password = async (email: string) => { + const rs = get(`${base.api_v2_url}/email/password`, { + email: email + }) + return base.buildResponse(await rs) +} + +export default password diff --git a/src/api/v2/user/password.api.ts b/src/api/v2/user/password.api.ts index a0c48c9..1ac2ebd 100644 --- a/src/api/v2/user/password.api.ts +++ b/src/api/v2/user/password.api.ts @@ -2,11 +2,12 @@ import base from '@/api/base' //@ts-ignore import { post } from '@/utils/request' -const password = async (username: string, old_password: string, new_password: string) => { +const password = async (username: string | null, old_password: string | null, new_password: string, verify_code: string | null) => { const rs = await post(`${base.api_v2_url}/user/password`, { username: username, old_password: old_password, - new_password: new_password + new_password: new_password, + verify_code: verify_code }) return base.buildResponse(rs) } diff --git a/src/components/UserInfo.vue b/src/components/UserInfo.vue index 5fe31a5..6f3bfca 100644 --- a/src/components/UserInfo.vue +++ b/src/components/UserInfo.vue @@ -313,7 +313,7 @@ async function changePassword() { } let rs try { - rs = await api.v2.user.password(data.username, data.oldPassword, data.newPassword) + rs = await api.v2.user.password(data.username, data.oldPassword, data.newPassword, null) } catch (e) { logger.error(e) tPassword.value.isLoading = false diff --git a/src/utils/request.js b/src/utils/request.js index 2791f39..bcd141c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -24,7 +24,6 @@ const instance = axios.create({ const tokenDomains = [ 'api.locyanfrp.cn', 'api-v2.locyanfrp.cn', - 'api-v2-next.locyanfrp.cn', 'localhost' ] diff --git a/src/views/auth/ResetPasswordView.vue b/src/views/auth/ResetPasswordView.vue index cf159e2..4c14f22 100644 --- a/src/views/auth/ResetPasswordView.vue +++ b/src/views/auth/ResetPasswordView.vue @@ -11,11 +11,11 @@ id="item" v-show="sendResetEmail" > - + @@ -32,7 +32,7 @@ - + - +
@@ -74,14 +74,15 @@ const sendResetEmail = ref(true) const model = ref([ { - username: '' + email: '' } ]) -const reset_password = ref([ +const resetPassword = ref([ { password: '', - confirm: '' + confirmPassword: '', + verify_code: '' } ]) @@ -93,22 +94,27 @@ if (code !== null) { } async function doResetRequest() { + if (resetPassword.value.password !== resetPassword.value.confirmPassword) { + message.error('两次输入的密码不一致,请核对') + return + } if (code === '' || code === undefined) { message.error('非法请求!') return } - if (status.value === 'reseting') { + if (status.value === 'working') { message.warning('上一个请求正在处理!') return } - status.value = 'reseting' + status.value = 'working' ldb.start() let rs try { - rs = await api.v1.User.DoResetPassword( - reset_password.value.password, - reset_password.value.confirm, + rs = await api.v2.user.password( + model.value.email, + null, + resetPassword.value.password, code ) } catch (e) { @@ -140,9 +146,9 @@ async function sendResetMail() { ldb.start() let rs try { - rs = await api.v1.User.DoResetPasswordEmailSend(model.value.username) + rs = await api.v2.email.password(model.value.email) } catch (e) { - message.error('请求' + e) + message.error('请求失败: ' + e) } if (!rs) { ldb.error() @@ -162,7 +168,7 @@ async function sendResetMail() { } const rules = { - username: { + email: { required: true, trigger: ['blur', 'input'], message: '请输入用户名' From 338f268afe498489bde8795acfa4c2d8534d14be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Thu, 17 Oct 2024 01:11:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[*]=20=E9=80=82=E9=85=8D=E6=96=B0=20API=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/v2/email/password.api.ts | 4 +- src/api/v2/user/password.api.ts | 7 +- src/utils/request.js | 6 +- src/views/auth/RegisterView.vue | 19 ++- src/views/auth/ResetPasswordView.vue | 216 +++++++++++++++++---------- 5 files changed, 164 insertions(+), 88 deletions(-) diff --git a/src/api/v2/email/password.api.ts b/src/api/v2/email/password.api.ts index 1b122c5..e7a1d77 100644 --- a/src/api/v2/email/password.api.ts +++ b/src/api/v2/email/password.api.ts @@ -2,9 +2,9 @@ import { get } from '@/utils/request' import base from '@/api/base' -const password = async (email: string) => { +const password = async (username: string) => { const rs = get(`${base.api_v2_url}/email/password`, { - email: email + username: username }) return base.buildResponse(await rs) } diff --git a/src/api/v2/user/password.api.ts b/src/api/v2/user/password.api.ts index 1ac2ebd..6f3bcdd 100644 --- a/src/api/v2/user/password.api.ts +++ b/src/api/v2/user/password.api.ts @@ -2,7 +2,12 @@ import base from '@/api/base' //@ts-ignore import { post } from '@/utils/request' -const password = async (username: string | null, old_password: string | null, new_password: string, verify_code: string | null) => { +const password = async ( + username: string, + old_password: string | null, + new_password: string, + verify_code: string | null +) => { const rs = await post(`${base.api_v2_url}/user/password`, { username: username, old_password: old_password, diff --git a/src/utils/request.js b/src/utils/request.js index bcd141c..4b371dc 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -21,11 +21,7 @@ const instance = axios.create({ timeout: 80000 }) -const tokenDomains = [ - 'api.locyanfrp.cn', - 'api-v2.locyanfrp.cn', - 'localhost' -] +const tokenDomains = ['api.locyanfrp.cn', 'api-v2.locyanfrp.cn', 'localhost'] // post请求的时候,我们需要加上一个请求头,所以可以在这里进行一个默认的设置,即设置post的请求头为 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' diff --git a/src/views/auth/RegisterView.vue b/src/views/auth/RegisterView.vue index 385d4a6..ab35b05 100644 --- a/src/views/auth/RegisterView.vue +++ b/src/views/auth/RegisterView.vue @@ -40,6 +40,9 @@ > {{ verify.msg }} + {{ verify.resendTimer }}s @@ -86,7 +89,8 @@ const model = ref([ const verify = ref({ isClick: false, - msg: `发送验证码` + msg: `发送验证码`, + resendTimer: 0 }) async function sendCode() { @@ -104,10 +108,23 @@ async function sendCode() { if (rs.status === 200) { message.success('已发送,若未收到请检查收件箱') verify.value.msg = `已发送` + verify.value.resendTimer = 60 + let timer = () => + setTimeout(() => { + if (verify.value.resendTimer !== 0) { + verify.value.resendTimer-- + timer() + } else { + verify.value.msg = `发送验证码` + verify.value.isClick = false + } + }, 1000) + timer() } else { message.error(rs.message) verify.value.isClick = false verify.value.msg = `发送验证码` + verify.value.resendTimer = 0 } ldb.finish() // logger.info('处理发送邮件验证代码事件完毕') diff --git a/src/views/auth/ResetPasswordView.vue b/src/views/auth/ResetPasswordView.vue index 4c14f22..bffffe9 100644 --- a/src/views/auth/ResetPasswordView.vue +++ b/src/views/auth/ResetPasswordView.vue @@ -10,50 +10,90 @@ size="medium" id="item" v-show="sendResetEmail" - > - - - -
- - - 发送邮件 - - - 登录 - - -
- - - + - - + + + + + + + + + + + + + + {{ verify.msg }} + + {{ verify.resendTimer }}s + +
提交 + + + + + 登录 +
+ + + + + + + + + + + + + + + + + + + + + + + + @@ -69,53 +109,55 @@ import logger from '@/utils/logger' const formRef = ref(null) const message = useMessage() const ldb = useLoadingBar() -const status = ref('init') const sendResetEmail = ref(true) const model = ref([ { - email: '' - } -]) - -const resetPassword = ref([ - { + username: '', password: '', confirmPassword: '', - verify_code: '' + verifyCode: '' } ]) +const verify = ref({ + isClick: false, + msg: `发送验证码`, + resendTimer: 0 +}) + +// const resetPassword = ref([ +// { +// password: '', +// confirmPassword: '', +// verify_code: '' +// } +// ]) + // 检查是否存在redirect值 -const code = getUrlKey('code') -if (code !== null) { - logger.info('重置密码标识符: ' + code) - sendResetEmail.value = false -} +// const code = getUrlKey('code') +// if (code !== null) { +// logger.info('重置密码标识符: ' + code) +// sendResetEmail.value = false +// } async function doResetRequest() { - if (resetPassword.value.password !== resetPassword.value.confirmPassword) { + if (model.value.password !== model.value.confirmPassword) { message.error('两次输入的密码不一致,请核对') return } - if (code === '' || code === undefined) { - message.error('非法请求!') - return - } - - if (status.value === 'working') { - message.warning('上一个请求正在处理!') - return - } - status.value = 'working' + // if (code === '' || code === undefined) { + // message.error('非法请求!') + // return + // } ldb.start() let rs try { rs = await api.v2.user.password( - model.value.email, + model.value.username, null, - resetPassword.value.password, - code + model.value.password, + model.value.verifyCode ) } catch (e) { message.error('请求重置密码失败: ' + e) @@ -125,53 +167,69 @@ async function doResetRequest() { return } if (rs.status === 200) { - if (rs.data.status) { - message.success(rs.message) - } else { - message.error(rs.message) - } + message.success(rs.message) } else { message.error(rs.message) } ldb.finish() - status.value = 'complete' } async function sendResetMail() { - if (status.value === 'sending') { - message.warning('上一个请求正在处理!') - return - } - status.value = 'sending' + verify.value.isClick = true + verify.value.msg = `正在处理` ldb.start() let rs try { - rs = await api.v2.email.password(model.value.email) + rs = await api.v2.email.password(model.value.username) } catch (e) { message.error('请求失败: ' + e) } if (!rs) { ldb.error() + verify.value.msg = `发送验证码` + verify.value.isClick = false + verify.value.resendTimer = 0 return } if (rs.status === 200) { - if (rs.data.status) { - message.success(rs.message) - } else { - message.error(rs.message) - } + message.success(rs.message) + verify.value.msg = `已发送` + verify.value.resendTimer = 60 + let timer = () => + setTimeout(() => { + if (verify.value.resendTimer !== 0) { + verify.value.resendTimer-- + timer() + } else { + verify.value.msg = `发送验证码` + verify.value.isClick = false + } + }, 1000) + timer() } else { message.error(rs.message) + verify.value.msg = `发送验证码` + verify.value.isClick = false + verify.value.resendTimer = 0 } ldb.finish() - status.value = 'complete' } const rules = { - email: { + password: { + required: true, + trigger: ['blur', 'input'], + message: '请输入密码' + }, + confirm_password: { + required: true, + trigger: ['blur', 'input'], + message: '请确认密码' + }, + username: { required: true, trigger: ['blur', 'input'], - message: '请输入用户名' + message: '请输入用户名或邮箱' } } From fb5c38529eb3a5d1e6b296f94dc8d36735d1a8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Thu, 17 Oct 2024 01:15:17 +0800 Subject: [PATCH 3/4] =?UTF-8?q?[*]=20=E4=BF=AE=E6=94=B9=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/auth/LoginView.vue | 2 +- src/views/auth/RegisterView.vue | 2 +- src/views/auth/ResetPasswordView.vue | 12 +++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/views/auth/LoginView.vue b/src/views/auth/LoginView.vue index 4986a95..d1c1412 100644 --- a/src/views/auth/LoginView.vue +++ b/src/views/auth/LoginView.vue @@ -35,7 +35,6 @@ -->
- 登录 没有账户?去注册 + 登录
diff --git a/src/views/auth/RegisterView.vue b/src/views/auth/RegisterView.vue index ab35b05..2fb3f42 100644 --- a/src/views/auth/RegisterView.vue +++ b/src/views/auth/RegisterView.vue @@ -48,7 +48,6 @@
- 注册 已有账户?去登录 + 注册
diff --git a/src/views/auth/ResetPasswordView.vue b/src/views/auth/ResetPasswordView.vue index bffffe9..b97de02 100644 --- a/src/views/auth/ResetPasswordView.vue +++ b/src/views/auth/ResetPasswordView.vue @@ -53,20 +53,18 @@
- - 提交 - - - - - 登录 + 我想起密码了,带我去登录 + 提交 + + +
From e1f9ccbf8487dd60ef83b5f56fd0ce4ff87242b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Thu, 17 Oct 2024 01:18:31 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[*]=20=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=20API=20=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UserInfo.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/UserInfo.vue b/src/components/UserInfo.vue index 6f3bfca..6f9e472 100644 --- a/src/components/UserInfo.vue +++ b/src/components/UserInfo.vue @@ -214,9 +214,8 @@ async function sendChangeEmailCode() { ldb.start() let rs try { - rs = await api.v1.Account.SendEditMail( + rs = await api.v2.email.email( userData.getters.get_username, - userData.getters.get_token, tEmail.value.email ) } catch (e) { @@ -229,7 +228,7 @@ async function sendChangeEmailCode() { ldb.error() return } - if (rs.status) { + if (rs.status === 200) { message.success(rs.message) tEmail.value.verify.msg = ref(`已发送`) } else {