|
|
|
@ -47,6 +47,64 @@
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="login content" v-else-if='isValid'>
|
|
|
|
|
<div class="flex mt-10 h-full" v-if="app.id">
|
|
|
|
|
<div class="flex flex-col items-center w-1/2 justify-center">
|
|
|
|
|
<img class="rounded-full h-44 w-44" :src="oaer.local().icon">
|
|
|
|
|
<div class="mt-4 text-2xl">{{ oaer.local().nickname || oaer.local().username }}</div>
|
|
|
|
|
<div class="mt-4"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex flex-col w-1/2 gap-4">
|
|
|
|
|
<div class="flex items-center justify-start gap-4">
|
|
|
|
|
<img class="rounded-full h-16 w-16" :src="app.icon">
|
|
|
|
|
<div>{{ app.name }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-grow">
|
|
|
|
|
<div>您正在授权登录 <span class="font-bold text-xl">{{ app.name }}</span> </div>
|
|
|
|
|
|
|
|
|
|
<div class="mt-8 ml-8 flex flex-col gap-4">
|
|
|
|
|
<div class="auth-line">
|
|
|
|
|
<UToggle color="primary" :model-value="true" disabled />
|
|
|
|
|
<div class='auth-info'>Basic User Info</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="auth-line">
|
|
|
|
|
<UToggle color="primary" v-model="app_perm.fs[0]" />
|
|
|
|
|
<div class='auth-info flex'>
|
|
|
|
|
<UInput v-if="app_perm.fs[0]" :padded="false" v-model="app_perm.fs[1]"
|
|
|
|
|
placeholder="userfile auth scope" variant="none" class="w-full border-b-black border-b-2" />
|
|
|
|
|
<span v-else>userfile permission</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex">
|
|
|
|
|
<button style="" @click="signout" class='ok back voa-btn'>
|
|
|
|
|
Sign out
|
|
|
|
|
</button>
|
|
|
|
|
<button @click="redirect()" class='ok voa-btn'>
|
|
|
|
|
Sign in
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="text-sm text-gray-600 text-center">
|
|
|
|
|
Authorizing will redirect to {{ app.init_url }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex mt-10 h-full justify-center items-center flex-col" v-else>
|
|
|
|
|
<img class="rounded-full h-44 w-44" :src="oaer.local().icon">
|
|
|
|
|
<div class="mt-4 text-2xl">{{ oaer.local().nickname || oaer.local().username }}</div>
|
|
|
|
|
<div class="flex-grow"></div>
|
|
|
|
|
<div class="flex w-1/2">
|
|
|
|
|
<button style="" @click="signout" class='ok back voa-btn'>
|
|
|
|
|
Sign out
|
|
|
|
|
</button>
|
|
|
|
|
<button @click="redirect()" class='ok voa-btn'>
|
|
|
|
|
Sign in
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="login content flex flex-col justify-between" v-else>
|
|
|
|
|
<div :check="checks.u" class="username mt-8">
|
|
|
|
|
<input @change="check" v-model="data.username" autocomplete="username"
|
|
|
|
@ -56,8 +114,8 @@
|
|
|
|
|
<input @change="check" v-model="data.password" autocomplete="password" type='password'
|
|
|
|
|
placeholder="password">
|
|
|
|
|
</div>
|
|
|
|
|
<button @click="login" class='ok voa-btn'>
|
|
|
|
|
login
|
|
|
|
|
<button @click="signin" class='ok voa-btn'>
|
|
|
|
|
Sign in
|
|
|
|
|
</button>
|
|
|
|
|
<div class="last">
|
|
|
|
|
<div class="icos">
|
|
|
|
@ -74,36 +132,23 @@
|
|
|
|
|
</Transition>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- <div class="h-full w-full flex items-center justify-center"> -->
|
|
|
|
|
<!-- <div class="px-10 pb-9 pt-16 rounded-xl w-96 bg-gray-50 relative"> -->
|
|
|
|
|
<!-- <img class='vico' :src="'/favicon.ico'"> -->
|
|
|
|
|
<!-- <Vinput class="mb-8" v-model="data.username" label="用户名" :validate="" /> -->
|
|
|
|
|
<!-- <Vinput class='mb-8' v-model="data.password" label='密码' :validate="" type="password" /> -->
|
|
|
|
|
<!-- <div class="flex justify-around mt-4"> -->
|
|
|
|
|
<!-- <div class='vbtn bg-green-300' @click="$router.push({ -->
|
|
|
|
|
<!-- name: -->
|
|
|
|
|
<!-- 'register' -->
|
|
|
|
|
<!-- })">注册</div> -->
|
|
|
|
|
<!-- <div class='vbtn bg-green-300' @click="onSubmit">登录</div> -->
|
|
|
|
|
<!-- <div class='vbtn bg-gray-300' @click="onReset">重置 </div> -->
|
|
|
|
|
<!-- </div> -->
|
|
|
|
|
<!-- </div> -->
|
|
|
|
|
<!-- </div> -->
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import msg from '@veypi/msg';
|
|
|
|
|
import * as crypto from 'crypto-js'
|
|
|
|
|
import oaer from '@veypi/oaer'
|
|
|
|
|
import type { models } from '#imports';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
definePageMeta({
|
|
|
|
|
layout: false,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const app = useAppConfig()
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const isValid = ref(oaer.isValid())
|
|
|
|
|
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] })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = ref({
|
|
|
|
@ -113,7 +158,6 @@ let data = ref({
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let uReg = /^[\w]{5,}$/
|
|
|
|
|
let pReg = /^[\w@_#]{6,}$/
|
|
|
|
|
let checks = ref({ 'u': true, 'p': true, 'p2': true })
|
|
|
|
@ -134,7 +178,11 @@ function deriveKey(password: string, salt: any) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const login = () => {
|
|
|
|
|
const signout = () => {
|
|
|
|
|
oaer.logout()
|
|
|
|
|
isValid.value = false
|
|
|
|
|
}
|
|
|
|
|
const signin = () => {
|
|
|
|
|
enable_check.value = true
|
|
|
|
|
check()
|
|
|
|
|
if (!checks.value.u || !checks.value.p) {
|
|
|
|
@ -155,7 +203,7 @@ const login = () => {
|
|
|
|
|
user_id: id, code: p.toString(), salt:
|
|
|
|
|
salt.toString()
|
|
|
|
|
}).then(e => {
|
|
|
|
|
oaer.init(app.host, e).then(() => {
|
|
|
|
|
oaer.init('', '', e).then(() => {
|
|
|
|
|
redirect("")
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.warn(e)
|
|
|
|
@ -171,32 +219,6 @@ const login = () => {
|
|
|
|
|
console.warn(e)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// api.user.salt(data.value.username).then((e: any) => {
|
|
|
|
|
// let id = e.data.id
|
|
|
|
|
// let key = deriveKey(data.value.password, e.data.salt)
|
|
|
|
|
// let salt = crypto.lib.WordArray.random(128 / 8)
|
|
|
|
|
// let opts = {
|
|
|
|
|
// iv: salt,
|
|
|
|
|
// mode: crypto.mode.CBC,
|
|
|
|
|
// padding: crypto.pad.Pkcs7
|
|
|
|
|
// }
|
|
|
|
|
// let p = crypto.AES.encrypt(id, key, opts)
|
|
|
|
|
// api.user.token(id, p.toString(), salt.toString()).then(e => {
|
|
|
|
|
// console.log(e)
|
|
|
|
|
// })
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// api.user.login(data.value.username,
|
|
|
|
|
// { client: 'vvv', typ: 'sss', pwd: Base64.encodeURL(data.value.password) }).then((data: any) => {
|
|
|
|
|
// util.setToken(data.auth_token)
|
|
|
|
|
// // msg.Info('登录成功')
|
|
|
|
|
// // user.fetchUserData()
|
|
|
|
|
// let url = route.query.redirect || data.redirect || ''
|
|
|
|
|
// console.log([url])
|
|
|
|
|
// redirect(url)
|
|
|
|
|
// }).catch(e => {
|
|
|
|
|
// msg.Warn(e)
|
|
|
|
|
// })
|
|
|
|
|
}
|
|
|
|
|
const register = () => {
|
|
|
|
|
enable_check.value = true
|
|
|
|
@ -223,26 +245,36 @@ const reset = () => {
|
|
|
|
|
check()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let uuid = computed(() => {
|
|
|
|
|
return route.query.uuid
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let ifLogOut = computed(() => {
|
|
|
|
|
return route.query.logout === '1'
|
|
|
|
|
})
|
|
|
|
|
let aOpt = ref('' as '' | 'newbie' | 'oh_no')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function redirect(url: string) {
|
|
|
|
|
function redirect(url?: string) {
|
|
|
|
|
if (url === 'undefined') {
|
|
|
|
|
url = ''
|
|
|
|
|
}
|
|
|
|
|
if (uuid.value && uuid.value !== app.id) {
|
|
|
|
|
api.app.Get(uuid.value as string).then((app) => {
|
|
|
|
|
api.token.Post({
|
|
|
|
|
refresh: '',
|
|
|
|
|
user_id: uuid.value as string,
|
|
|
|
|
app_id: uuid.value as string,
|
|
|
|
|
if (route.query.redirect) {
|
|
|
|
|
url = route.query.redirect as string
|
|
|
|
|
}
|
|
|
|
|
let uuid = route.query.uuid as string
|
|
|
|
|
if (uuid) {
|
|
|
|
|
oaer.api().app.Get(uuid as string).then((app) => {
|
|
|
|
|
if (uuid === oaer.logic().oa_id) {
|
|
|
|
|
oaer.goto(url || app.init_url || '/')
|
|
|
|
|
} else {
|
|
|
|
|
let perm = []
|
|
|
|
|
for (let i in app_perm.value) {
|
|
|
|
|
let p = app_perm.value[i]
|
|
|
|
|
if (p[0]) {
|
|
|
|
|
perm.push({
|
|
|
|
|
name: i,
|
|
|
|
|
tid: p[1],
|
|
|
|
|
level: p[2]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
oaer.api().token.Post({
|
|
|
|
|
refresh: oaer.logic().token.refresh.raw(),
|
|
|
|
|
app_id: uuid,
|
|
|
|
|
over_perm: JSON.stringify(perm)
|
|
|
|
|
}).then(e => {
|
|
|
|
|
url = url || app.init_url
|
|
|
|
|
// let data = JSON.parse(Base64.decode(e.split('.')[1]))
|
|
|
|
@ -250,42 +282,31 @@ function redirect(url: string) {
|
|
|
|
|
e = encodeURIComponent(e)
|
|
|
|
|
if (url.indexOf('$token') >= 0) {
|
|
|
|
|
url = url.replaceAll('$token', e)
|
|
|
|
|
} else {
|
|
|
|
|
url = buildURL(url, 'token=' + e)
|
|
|
|
|
}
|
|
|
|
|
window.location.href = url
|
|
|
|
|
|
|
|
|
|
oaer.goto(url, { 'token': e })
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else if (url) {
|
|
|
|
|
router.push(url)
|
|
|
|
|
oaer.goto(url)
|
|
|
|
|
} else {
|
|
|
|
|
router.push('/')
|
|
|
|
|
}
|
|
|
|
|
oaer.goto('/')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildURL(url: string, params?: string) {
|
|
|
|
|
if (!params) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// params序列化过程略
|
|
|
|
|
var hashmarkIndex = url.indexOf('#');
|
|
|
|
|
if (hashmarkIndex !== -1) {
|
|
|
|
|
url = url.slice(0, hashmarkIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url += (url.indexOf('?') === -1 ? '?' : '&') + params;
|
|
|
|
|
|
|
|
|
|
return url;
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
let uuid = route.query.uuid as string
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
if (ifLogOut.value) {
|
|
|
|
|
util.setToken('')
|
|
|
|
|
} else if (util.checkLogin()) {
|
|
|
|
|
console.log(util.checkLogin())
|
|
|
|
|
redirect(route.query.redirect as string || '')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
@ -303,6 +324,13 @@ onMounted(() => {
|
|
|
|
|
/* backdrop-filter: blur(5px); */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auth-line {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
|
|
|
|
.auth-info {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.box {
|
|
|
|
|
user-select: none;
|
|
|
|
|
position: sticky;
|
|
|
|
|