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..e7a1d77
--- /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 (username: string) => {
+ const rs = get(`${base.api_v2_url}/email/password`, {
+ username: username
+ })
+ 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..6f3bcdd 100644
--- a/src/api/v2/user/password.api.ts
+++ b/src/api/v2/user/password.api.ts
@@ -2,11 +2,17 @@ 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,
+ 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..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 {
@@ -313,7 +312,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..4b371dc 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -21,12 +21,7 @@ const instance = axios.create({
timeout: 80000
})
-const tokenDomains = [
- 'api.locyanfrp.cn',
- 'api-v2.locyanfrp.cn',
- 'api-v2-next.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/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 385d4a6..2fb3f42 100644
--- a/src/views/auth/RegisterView.vue
+++ b/src/views/auth/RegisterView.vue
@@ -40,12 +40,14 @@
>
{{ 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 cf159e2..b97de02 100644
--- a/src/views/auth/ResetPasswordView.vue
+++ b/src/views/auth/ResetPasswordView.vue
@@ -10,50 +10,88 @@
size="medium"
id="item"
v-show="sendResetEmail"
- >
-
-
-
-
-
-
- 发送邮件
-
- router.push({ name: 'Login' })">
- 登录
-
-
-
-
-
-
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+ {{ verify.msg }}
+
+ {{ verify.resendTimer }}s
+
+
-
- 提交
+ router.push({ name: 'Login' })"
+ >
+ 我想起密码了,带我去登录
+ 提交
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -69,47 +107,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([
{
- username: ''
- }
-])
-
-const reset_password = ref([
- {
+ username: '',
password: '',
- confirm: ''
+ confirmPassword: '',
+ 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 (code === '' || code === undefined) {
- message.error('非法请求!')
- return
- }
-
- if (status.value === 'reseting') {
- message.warning('上一个请求正在处理!')
+ if (model.value.password !== model.value.confirmPassword) {
+ message.error('两次输入的密码不一致,请核对')
return
}
- status.value = 'reseting'
+ // if (code === '' || code === undefined) {
+ // message.error('非法请求!')
+ // return
+ // }
ldb.start()
let rs
try {
- rs = await api.v1.User.DoResetPassword(
- reset_password.value.password,
- reset_password.value.confirm,
- code
+ rs = await api.v2.user.password(
+ model.value.username,
+ null,
+ model.value.password,
+ model.value.verifyCode
)
} catch (e) {
message.error('请求重置密码失败: ' + e)
@@ -119,53 +165,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.v1.User.DoResetPasswordEmailSend(model.value.username)
+ rs = await api.v2.email.password(model.value.username)
} catch (e) {
- message.error('请求' + 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 = {
+ password: {
+ required: true,
+ trigger: ['blur', 'input'],
+ message: '请输入密码'
+ },
+ confirm_password: {
+ required: true,
+ trigger: ['blur', 'input'],
+ message: '请确认密码'
+ },
username: {
required: true,
trigger: ['blur', 'input'],
- message: '请输入用户名'
+ message: '请输入用户名或邮箱'
}
}