Skip to content

Commit

Permalink
feat: 添加了解密用户信息相关的页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Zecyel committed Aug 5, 2024
1 parent 095607c commit bcb7c93
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 2 deletions.
57 changes: 57 additions & 0 deletions pages/decrypt/history.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<el-text class="mx-1" style="margin: 5px;">Identity Name</el-text>
<el-input
v-model="identity_name"
clearable
/>
<!-- TODO: I need a fake identity-name for placeholder -->
<div style="margin: 20px;" />
<el-button type="primary" @click="query">查询</el-button>
<template v-if="history.length > 0">
<div style="margin: 20px;" />
<el-table :data="history" style="width: 100%">
<el-table-column prop="user_id" label="User ID"/>
<el-table-column prop="pgp_message" label="PGP Message"/>
</el-table>
</template>
</template>

<script setup lang="ts">
import { getPGPMessageSchema } from '~/api/shamir/decrypt';
import { callApi } from '~/util/callApi';
const layoutStore = useLayoutStore();
layoutStore.title = "我的解密历史"
layoutStore.path = [
{ name: "Home", path: "/" },
{ name: "Decrypt" },
{ name: "History" }
]
const identity_name = ref('')
const history = ref([])
async function query() {
const { type, data } = await callApi(getPGPMessageSchema, {
identity_name: identity_name.value
})
if (type !== 'success') {
ElNotification({
title: '查询失败',
message: data.message,
position: 'bottom-right',
type: 'error'
})
} else {
ElNotification({
title: '查询成功',
position: 'bottom-right',
type: 'success'
})
history.value = data
}
}
</script>
92 changes: 92 additions & 0 deletions pages/decrypt/status.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<el-text class="mx-1" style="margin: 5px;">User ID</el-text>
<el-input
v-model="user_id"
clearable
/>
<div style="margin: 20px;" />
<el-button type="primary" @click="query">查询</el-button>
<div style="margin: 20px;" />

<template v-if="visibility">
<el-text class="mx-1" style="margin: 5px;">解密状态:{{ status ? '已' : '未' }}解密</el-text>
<div style="margin: 10px;" />

<el-text class="mx-1" style="margin: 5px;">参与解密者</el-text>
<div style="margin: 10px;" />

<ul>
<li v-for="identity_name in identity_names" :key="identity_name">{{ identity_name }}</li>
</ul>

<div style="margin: 10px;" />

<el-text class="mx-1" style="margin: 5px;" v-if="status">解密后的邮箱:{{ email }}</el-text>
</template>
</template>

<script setup lang="ts">
import { getDecryptStatusSchema, getDecryptedEmailSchema } from '~/api/shamir/decrypt';
import { callApi } from '~/util/callApi';
const layoutStore = useLayoutStore();
layoutStore.title = "查询解密状态"
layoutStore.path = [
{ name: "Home", path: "/" },
{ name: "Decrypt" },
{ name: "Status" }
]
const user_id = ref('')
const visibility = ref(false)
const status = ref(false)
const identity_names = ref([])
const email = ref('')
async function query() {
const { type, data } = await callApi(getDecryptStatusSchema, {}, {
user_id: user_id.value
})
if (type !== 'success') {
ElNotification({
title: '查询失败',
message: data.message,
position: 'bottom-right',
type: 'error'
})
return
}
status.value = data.shamir_upload_ready
identity_names.value = data.uploaded_shares_identity_names
if (status.value) {
const { type, data } = await callApi(getDecryptedEmailSchema, {}, {
user_id: user_id.value
})
if (type !== 'success') {
ElNotification({
title: '查询失败',
message: data.message,
position: 'bottom-right',
type: 'error'
})
return
}
email.value = data.user_email
}
ElNotification({
title: '查询成功',
position: 'bottom-right',
type: 'success'
})
visibility.value = true
}
</script>
78 changes: 78 additions & 0 deletions pages/decrypt/upload.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<el-text class="mx-1" style="margin: 5px;">User ID</el-text>
<el-input
v-model="user_id"
clearable
/>
<div style="margin: 10px;" />
<el-text class="mx-1" style="margin: 5px;">Identity Name</el-text>
<el-input
v-model="identity_name"
clearable
/>
<div style="margin: 10px;" />
<el-text class="mx-1" style="margin: 5px;">Share</el-text>
<el-input
v-model="share"
:rows="3"
type="textarea"
clearable
/>
<div style="margin: 20px;" />
<el-button type="primary" @click="upload">上传</el-button>
</template>

<script setup lang="ts">
import { decryptSchema } from '~/api/shamir/decrypt';
import { callApi } from '~/util/callApi';
const layoutStore = useLayoutStore();
layoutStore.title = "上传解密后数据"
layoutStore.path = [
{ name: "Home", path: "/" },
{ name: "Decrypt" },
{ name: "Upload" }
]
const identity_name = ref('')
const share = ref('')
const user_id = ref('')
async function upload() {
const userid = parseInt(user_id.value)
if (isNaN(userid)) {
ElNotification({
title: '上传失败',
message: 'User ID 必须为数字',
position: 'bottom-right',
type: 'error'
})
return
}
const { type, data } = await callApi(decryptSchema, {
identity_name: identity_name.value,
share: share.value,
user_id: userid
})
console.log(type, data)
if (type === 'success') {
ElNotification({
title: '上传成功',
message: data.message,
position: 'bottom-right',
type: 'success'
})
} else {
ElNotification({
title: '上传失败',
message: data.message,
position: 'bottom-right',
type: 'error'
})
}
}
</script>
5 changes: 4 additions & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const target = [
// { desc: "User", path: "/user" },
// { desc: "Treehole", path: "/treehole" }
{ desc: "茶楼 Tag 管理", path: '/treehole/tag' },
{ desc: "发送站内信", path: '/treehole/message' }
{ desc: "发送站内信", path: '/treehole/message' },
{ desc: "我的解密历史", path: '/decrypt/history' },
{ desc: "上传解密后数据", path: '/decrypt/upload' },
{ desc: "查询解密状态", path: '/decrypt/status' }
]
</script>
1 change: 0 additions & 1 deletion pages/treehole/message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const message = ref('')
const receiver = ref('')
async function send() {
console.log(123)
const { type, data } = await callApi(sendMessageSchema, {
description: message.value,
recipients: receiver.value.split(',').map(Number).filter(Boolean)
Expand Down

0 comments on commit bcb7c93

Please sign in to comment.