feat: user

v3
veypi 3 weeks ago
parent fe0f3b07d0
commit 11521b4b1c

@ -15,14 +15,15 @@ export function TokenSalt(json: TokenSaltOpts) {
return webapi.Post<{ id: string, salt: string }>(`/token/salt`, { json }) return webapi.Post<{ id: string, salt: string }>(`/token/salt`, { json })
} }
export interface PostOpts { export interface PostOpts {
user_id: string refresh?: string
typ?: 'app' | 'ufs'
user_id?: string
salt?: string salt?: string
code?: string code?: string
app_id?: string app_id?: string
expired_at?: Date expired_at?: Date
over_perm?: string over_perm?: string
device?: string device?: string
refresh?: string
} }
// keep // keep
@ -48,6 +49,7 @@ export function Delete(token_id: string) {
export interface ListOpts { export interface ListOpts {
user_id: string user_id: string
app_id: string app_id: string
limit: number
} }
export function List(json: ListOpts) { export function List(json: ListOpts) {
return webapi.Get<models.Token[]>(`/token`, { json }) return webapi.Get<models.Token[]>(`/token`, { json })

@ -149,7 +149,10 @@ interface data {
function transData(d: data) { function transData(d: data) {
let opts = { params: d.query, data: {}, headers: {} as any } let opts = { headers: {} } as any
if (d.query) {
opts.params = d.query
}
if (d.form) { if (d.form) {
opts.data = d.form opts.data = d.form
opts.headers['content-type'] = 'application/x-www-form-urlencoded' opts.headers['content-type'] = 'application/x-www-form-urlencoded'

@ -147,9 +147,33 @@ definePageMeta({
const route = useRoute() const route = useRoute()
const isValid = ref(oaer.isValid()) const isValid = ref(oaer.isValid())
const uuid = ref(route.query.uuid as string)
const app = ref<models.App>({} as models.App) const app = ref<models.App>({} as models.App)
const app_perm = ref<{ [key: string]: [boolean, string, number] }>({ 'fs': [true, '/', 4], 'app': [true, '', 1], 'user': [true, '', 1] }) const app_perm = ref<{ [key: string]: [boolean, string, number] }>({ 'fs': [true, '/', 4], 'app': [true, '', 1], 'user': [true, '', 1] })
const auto_redirect = () => {
if (isValid.value) {
if (uuid.value) {
api.app.Get(uuid.value).then(e => {
app.value = e
console.log(oaer.local())
api.token.List({ limit: 1, app_id: uuid.value, user_id: oaer.local().id }).then(e => {
console.log(e)
})
}).catch(e => {
if (e.code === 40401) {
msg.Warn('参数错误: 该应用不存在')
uuid.value = ''
redirect()
return
}
console.warn(e)
})
} else {
redirect()
}
}
}
let data = ref({ let data = ref({
username: '', username: '',
@ -204,7 +228,9 @@ const signin = () => {
salt.toString() salt.toString()
}).then(e => { }).then(e => {
oaer.init('', '', e).then(() => { oaer.init('', '', e).then(() => {
redirect("") isValid.value = true
auto_redirect()
// redirect("")
}).catch((e) => { }).catch((e) => {
console.warn(e) console.warn(e)
msg.Warn('登录失败:' + (e?.err || e)) msg.Warn('登录失败:' + (e?.err || e))
@ -254,10 +280,9 @@ function redirect(url?: string) {
if (route.query.redirect) { if (route.query.redirect) {
url = route.query.redirect as string url = route.query.redirect as string
} }
let uuid = route.query.uuid as string if (uuid.value) {
if (uuid) { api.app.Get(uuid.value).then((app) => {
oaer.api().app.Get(uuid as string).then((app) => { if (uuid.value === oaer.logic().oa_id) {
if (uuid === oaer.logic().oa_id) {
oaer.goto(url || app.init_url || '/') oaer.goto(url || app.init_url || '/')
} else { } else {
let perm = [] let perm = []
@ -271,9 +296,9 @@ function redirect(url?: string) {
}) })
} }
} }
oaer.api().token.Post({ api.token.Post({
refresh: oaer.logic().token.refresh.raw(), refresh: oaer.logic().token.refresh.raw(),
app_id: uuid, app_id: uuid.value,
over_perm: JSON.stringify(perm) over_perm: JSON.stringify(perm)
}).then(e => { }).then(e => {
url = url || app.init_url url = url || app.init_url
@ -295,19 +320,7 @@ function redirect(url?: string) {
} }
onMounted(() => { onMounted(() => {
let uuid = route.query.uuid as string auto_redirect()
if (isValid.value && uuid) {
oaer.api().app.Get(uuid).then(e => {
app.value = e
}).catch(e => {
if (e.code === 40401) {
msg.Warn('参数错误: 该应用不存在')
return
}
console.warn(e)
})
}
}) })
</script> </script>

@ -1,4 +1,4 @@
<!-- <!--
* user.vue * user.vue
* Copyright (C) 2024 veypi <i@veypi.com> * Copyright (C) 2024 veypi <i@veypi.com>
* 2024-06-06 16:32 * 2024-06-06 16:32
@ -6,12 +6,91 @@
--> -->
<template> <template>
<div> <div>
user <h1 class="page-h1">账号设置</h1>
<div class="flex justify-center pt-10">
<crud ref="table" editable :keys="keys" :data="[oaer.local()]" @update="newData = $event[0]">
<template #k_icon="{ value, set }">
<div class="w-full flex justify-center">
<uploader class="" @success="set" dir="/usr/icon">
<img class="rounded-full h-8 w-8" :src="value">
</uploader>
</div>
</template>
<template #k_pass>
<div class="vbtn" @click="prompt = true" size='sm' color='secondary'>修改</div>
</template>
</crud>
</div>
<UModal v-model="prompt" persistent>
<UCard style="min-width: 350px">
<template #header>
<div class="text-h6">请输入新密码</div>
</template>
<vinput type='password' class="my-8" v-model="pass[0]">
</vinput>
<vinput type='password' class="my-8" v-model="pass[1]">
</vinput>
<template #footer class="">
<div class="flex justify-end gap-8">
<div class="vbtn bg-vignore w-32" @click="prompt = false">{{ $t('c.cancel') }}</div>
<div class="vbtn bg-vprimary w-32" @click="reset">{{ $t('c.ok') }}</div>
</div>
</template>
</UCard>
</UModal>
<div v-if="newData" class="flex justify-center gap-8 mt-6">
<div class="vbtn bg-vignore w-32" @click="table.reload">{{ $t('c.cancel') }}</div>
<div class="vbtn bg-vprimary w-32" @click="save">{{ $t('c.ok') }}</div>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import msg from '@veypi/msg';
import oaer from '@veypi/oaer'
let prompt = ref(false)
let table = ref()
const keys = ref<any>([
{ name: 'id', label: 'ID', editable: false },
{ name: 'username', label: '用户名' },
{ name: 'pass', label: '密码' },
{ name: 'nickname', label: '昵称' },
{ name: 'icon', label: 'logo' },
{ name: 'email', label: '邮箱' },
{ name: 'phone', label: '手机号' },
])
const newData = ref()
const save = () => {
api.user.Patch(oaer.local().id, newData.value)
.then(e => {
msg.Info('更新成功')
Object.assign(oaer.logic().user, newData.value)
newData.value = null
}).catch(e => {
msg.Warn('更新失败 ' + e)
})
}
let pass = ref(['', ''])
const reset = () => {
if (pass.value[0] == '' || pass.value[1] == '') {
msg.Warn('密码不能为空')
return
}
if (pass.value[0] != pass.value[1]) {
msg.Warn('两次密码不一致')
return
}
prompt.value = false
// api.user.reset(u.id, pass.value[0]).then((e) => {
// msg.Info('')
// }).catch(e => {
// msg.Warn(' ' + e)
// })
}
</script> </script>
<style scoped></style> <style scoped></style>

Loading…
Cancel
Save