Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Daiyangcheng committed Dec 25, 2024
2 parents 99554d9 + 2e3b9fc commit e14368e
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/api/v2/auth/oauth/authorized/all.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 all = async (user_id: number) => {
const rs = get(`${base.api_v2_url}/auth/oauth/authorized/all`, {
user_id: user_id
})
return base.buildResponse(await rs)
}

export default all
13 changes: 13 additions & 0 deletions src/api/v2/auth/oauth/authorized/app.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ts-ignore
import { deleteReq } from '@/utils/request'
import base from '@/api/base'

const app = async (user_id: number, app_id: number | undefined) => {
const rs = deleteReq(`${base.api_v2_url}/auth/oauth/authorized/app`, {
user_id: user_id,
app_id: app_id
})
return base.buildResponse(await rs)
}

export default app
10 changes: 8 additions & 2 deletions src/api/v2/auth/oauth/authorized/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export default {
import all from './all.api'
import app from './app.api'
import session from './session.api'

}
export default {
all: all,
app: app,
session: session
}
Empty file.
14 changes: 14 additions & 0 deletions src/api/v2/auth/oauth/authorized/session.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ts-ignore
import { deleteReq } from '@/utils/request'
import base from '@/api/base'

const session = async (user_id: number, app_id: number, session_id: number | undefined) => {
const rs = deleteReq(`${base.api_v2_url}/auth/oauth/authorized/session`, {
user_id: user_id,
app_id: app_id,
session_id: session_id
})
return base.buildResponse(await rs)
}

export default session
4 changes: 3 additions & 1 deletion src/api/v2/auth/oauth/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import qq from './qq'
import permission from './permission'
import authorize from './authorize.api'
import authorized from './authorized'

export default {
qq: qq,
permission: permission,
authorize: authorize
authorize: authorize,
authorized: authorized
}
182 changes: 179 additions & 3 deletions src/views/apps/AccessManagementView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,183 @@
<i class="twa twa-identification-card"></i>
<n-text type="primary"> 授权管理</n-text>
</n-h1>
<n-h3>此页面仍在开发中🔧</n-h3>
<n-empty></n-empty>
<n-spin :show="loading">
<n-empty v-if="list.length === 0"></n-empty>
<n-card
v-else
v-for="app in list"
style="margin-bottom: 1rem"
content-style="padding: 0"
:title="app.name"
>
<n-text style="margin: 0 var(--n-padding-left) var(--n-padding-bottom) var(--n-padding-left)">
应用介绍: {{ app.description }}
</n-text>
<n-tabs type="line" size="large" :tabs-padding="20" pane-style="padding: 20px;">
<n-tab-pane name="授权信息">
<n-text>活动会话数: {{ app.sessions.length }}</n-text>
<br />
<n-text>已授予的权限:&nbsp;</n-text>
<n-text v-for="permissionId in app.authorizedPermissions">
{{ permissionList.filter((it) => it.id == permissionId)[0]['node']
}}{{ [...app.authorizedPermissions].reverse()[0] != permissionId ? ', ' : '' }}
</n-text>
</n-tab-pane>
<n-tab-pane style="padding-block: 0.5rem" name="活动会话">
<n-list style="margin-right: 2.5rem">
<n-list-item v-for="session in app.sessions" :key="session.id">
<n-text>会话 ID: {{ session.id }}</n-text>
<br />
<n-text>授权时间: {{ new Date(session.authorizeTime) }}</n-text>
<template #suffix>
<n-button type="error" @click="revokeSessionAuthorize(app.id, session.id)" secondary
>撤销授权</n-button
>
</template>
</n-list-item>
</n-list>
</n-tab-pane>
</n-tabs>
<template #action>
<n-button @click="revokeAppAuthorize(app.id)" type="error">撤销应用程序授权</n-button>
</template>
</n-card>
</n-spin>
</template>
<script setup lang="ts"></script>
<script setup lang="ts">
import userData from '@/utils/stores/userData/store'
import { ref, onMounted } from 'vue'
import api from '@/api'
import logger from '@/utils/logger'
import Message from '@/utils/message'
import Dialog from '@/utils/dialog'
const message = new Message()
const dialog = new Dialog()
const loading = ref(true)
const list = ref([])
const permissionList = ref([])
async function revokeAppAuthorize(appId: number | undefined) {
dialog.warning('确认要撤销授权吗?撤销后应用将不具有访问权限', {
onPositiveClick: async () => {
let rs
try {
rs = await api.v2.auth.oauth.authorized.app(userData.getters.get_user_id, appId)
} catch (e) {
logger.error(e)
message.error(e)
return false
}
if (!rs) return false
if (rs.status === 200) {
if (appId === undefined) list.value.clear()
else list.value = list.value.filter((it) => it.id != appId)
message.success('撤销授权成功')
} else {
message.error(rs.message)
}
}
})
}
async function revokeSessionAuthorize(appId: number, sessionId: number | undefined) {
dialog.warning('确认要撤销授权吗?撤销后应用将不具有访问权限', {
onPositiveClick: async () => {
let rs
try {
rs = await api.v2.auth.oauth.authorized.session(
userData.getters.get_user_id,
appId,
sessionId
)
} catch (e) {
logger.error(e)
message.error(e)
return false
}
if (!rs) return false
if (rs.status === 200) {
const newList = []
list.value.forEach((it) => {
if (it.it == appId) {
let item = it
item.session = item.session.filter((it) => it.id != sessionId)
newList.push(item)
} else {
newList.push(it)
}
})
message.success('撤销授权成功')
} else {
message.error(rs.message)
}
}
})
}
onMounted(async () => {
async function initPermissions(): Promise<boolean> {
let rs
try {
rs = await api.v2.auth.oauth.permission.all(userData.getters.get_user_id)
} catch (e) {
logger.error(e)
message.error(e)
return false
}
if (!rs) return false
if (rs.status === 200) {
// logger.info(rs.data)
permissionList.value = rs.data.list
return true
} else {
message.error(rs.message)
}
return false
}
async function initAuthorizedList(): Promise<boolean> {
let rs
try {
rs = await api.v2.auth.oauth.authorized.all(userData.getters.get_user_id)
} catch (e) {
logger.error(e)
message.error(e)
return false
}
if (!rs) return false
if (rs.status === 200) {
// logger.info(rs.data)
if (rs.data.list.length == 0) return true
rs.data.list.forEach((item) => {
let sessions = []
item.sessions.forEach((session) => {
sessions.push({
id: session.id,
authorizeTime: session.authorize_time
})
})
list.value.push({
id: item.app_id,
name: item.app_name,
description: item.app_description,
authorizedPermissions: item.authorized_permissions,
sessions: sessions
})
})
return true
} else {
message.error(rs.message)
}
return false
}
const init1 = await initPermissions()
const init2 = await initAuthorizedList()
if (init1 && init2) {
loading.value = false
}
})
</script>
14 changes: 12 additions & 2 deletions src/views/auth/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,18 @@
v-model="token"
@error="
(code) => {
showTurnstile = false
message.error(`验证码加载失败,错误代码: ${code}`)
if (code.startsWith(200)) {
message.error(`验证失败,状态异常,错误代码: ${code}`)
} else if (code.startsWith(300)) {
message.error(`验证失败,当前环境异常,错误代码: ${code}`)
} else if (code.startsWith(600)) {
message.error(`验证失败,错误代码: ${code}`)
} else {
message.error(`验证错误,错误代码: ${code}`)
}
setTimeout(() => {
showTurnstile = false
}, 3000)
}
"
@unsupported="
Expand Down

0 comments on commit e14368e

Please sign in to comment.