Skip to content

Commit

Permalink
[+] OAuth Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Daiyangcheng committed Feb 16, 2024
1 parent fd77742 commit ed4ada4
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
<template>
<n-grid cols="1" item-responsive>
<n-grid-item span="1">
<n-form
ref="formRef"
:model="model"
:rules="rules"
label-width="auto"
require-mark-placement="right-hanging"
size="medium"
id="item"
v-show="!other_login"
>
<n-form ref="formRef" :model="model" :rules="rules" label-width="auto" require-mark-placement="right-hanging"
size="medium" id="item" v-show="!other_login">
<n-form-item label="用户名 / 邮箱" path="username">
<n-input
type="text"
v-model:value="model.username"
placeholder="用户名"
@keyup.enter="login"
/>
<n-input type="text" v-model:value="model.username" placeholder="用户名" @keyup.enter="login" />
</n-form-item>
<n-form-item label="密码" path="password">
<n-input
type="password"
v-model:value="model.password"
placeholder="密码"
@keyup.enter="login"
/>
<n-input type="password" v-model:value="model.password" placeholder="密码" @keyup.enter="login" />
</n-form-item>
<div>
<n-space justify="space-between">
<n-button type="info" @click="qqlogin" :loading="qqlogin_loading"> QQ 登录 </n-button>
<n-space>
<n-button type="info" @click="qqlogin" :loading="qqlogin_loading"> QQ 登录 </n-button>
<n-button type="info" @click="oauthlogin" :loading="oauthlogin_loading"> OAuth 登录 </n-button>
</n-space>
<n-space justify="end">
<n-button type="primary" @click="login"> 登录</n-button>
<n-button ghost style="--n-border: none" type="primary" @click="goregister">
Expand All @@ -40,10 +25,7 @@
</div>
</n-form>
<div v-show="other_login">
<n-spin
description="正在进行第三方登录处理"
style="display: flex; justify-content: center; margin-top: 30vh"
></n-spin>
<n-spin description="正在进行第三方登录处理" style="display: flex; justify-content: center; margin-top: 30vh"></n-spin>
</div>
</n-grid-item>
</n-grid>
Expand All @@ -61,6 +43,7 @@ const message = useMessage()
const ldb = useLoadingBar()
const other_login = ref(false)
const qqlogin_loading = ref(false)
const oauthlogin_loading = ref(false)
const model = ref([
{
Expand All @@ -78,6 +61,7 @@ if (redirect !== null) {
// 检查是否存在第三方登录返回值
// 针对QQ登录的处理
const code = getUrlKey('code')
const token = getUrlKey('token')
if (code !== null) {
other_login.value = true
const rs = get(
Expand All @@ -94,10 +78,28 @@ if (code !== null) {
})
}
if (token !== null) {
other_login.value = true
const rs = get("https://api-v2.locyanfrp.cn/api/v2/oauth/loginByToken?token=" + token)
rs.then((res) => {
if (res.status === 200) {
message.success(res.data.username + ',欢迎回来!')
store.commit('set_token', res.data.token)
store.commit('set_user_info', res.data)
router.push(redirect || '/dashboard')
}
})
}
function goregister() {
router.push('/register')
}
function oauthlogin() {
oauthlogin_loading.value = true;
window.location.href = "https://api-v2.locyanfrp.cn/api/v2/oauth/authorize?redirectUrl=http://" + window.location.host + "/login";
}
function login() {
ldb.start()
if (
Expand Down

0 comments on commit ed4ada4

Please sign in to comment.