Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 email #33

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/api/v2/email/email.api.ts
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion src/api/v2/email/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions src/api/v2/email/password.api.ts
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions src/api/v2/user/password.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/UserInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/views/auth/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
</n-button>-->
</n-space>
<n-space justify="end">
<n-button type="primary" @click="login"> 登录</n-button>
<n-button
ghost
style="--n-border: none"
Expand All @@ -44,6 +43,7 @@
>
没有账户?去注册
</n-button>
<n-button type="primary" @click="login"> 登录</n-button>
</n-space>
</n-space>
</div>
Expand Down
21 changes: 19 additions & 2 deletions src/views/auth/RegisterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
>
{{ verify.msg }}
</n-button>
<n-text style="margin-left: 0.5rem" v-show="verify.resendTimer !== 0"
>{{ verify.resendTimer }}s</n-text
>
</n-grid-item>
</n-grid>
</n-form-item>
<div style="display: flex; margin-bottom: 20px; justify-content: flex-end">
<n-space>
<n-button type="primary" @click="register" style="margin-right: 10px"> 注册 </n-button>
<n-button
ghost
type="primary"
Expand All @@ -54,6 +56,7 @@
>
已有账户?去登录
</n-button>
<n-button type="primary" @click="register"> 注册 </n-button>
</n-space>
</div>
</n-form>
Expand Down Expand Up @@ -86,7 +89,8 @@ const model = ref([

const verify = ref({
isClick: false,
msg: `发送验证码`
msg: `发送验证码`,
resendTimer: 0
})

async function sendCode() {
Expand All @@ -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('处理发送邮件验证代码事件完毕')
Expand Down
Loading