egirlskey/packages/frontend/src/pages/miauth.vue

110 lines
2.7 KiB
Vue
Raw Normal View History

2020-03-28 02:24:37 +00:00
<template>
<MkStickyContainer>
2023-04-01 05:01:57 +00:00
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 07:20:53 +00:00
<MkSpacer :contentMax="800">
<div v-if="$i">
<div v-if="state == 'waiting'">
<MkLoading/>
</div>
<div v-if="state == 'denied'">
<p>{{ i18n.ts._auth.denied }}</p>
</div>
<div v-else-if="state == 'accepted'" class="accepted">
<p v-if="callback">{{ i18n.ts._auth.callback }}<MkEllipsis/></p>
<p v-else>{{ i18n.ts._auth.pleaseGoBack }}</p>
</div>
<div v-else>
<div v-if="_permissions.length > 0">
2023-04-01 05:01:57 +00:00
<p v-if="name">{{ i18n.t('_auth.permission', { name }) }}</p>
2023-02-09 17:29:22 +00:00
<p v-else>{{ i18n.ts._auth.permissionAsk }}</p>
<ul>
2023-04-01 05:01:57 +00:00
<li v-for="p in _permissions" :key="p">{{ i18n.t(`_permissions.${p}`) }}</li>
</ul>
</div>
2023-04-01 05:01:57 +00:00
<div v-if="name">{{ i18n.t('_auth.shareAccess', { name }) }}</div>
2023-02-09 17:29:22 +00:00
<div v-else>{{ i18n.ts._auth.shareAccessAsk }}</div>
<div :class="$style.buttons">
<MkButton inline @click="deny">{{ i18n.ts.cancel }}</MkButton>
<MkButton inline primary @click="accept">{{ i18n.ts.accept }}</MkButton>
</div>
</div>
2020-03-28 02:24:37 +00:00
</div>
<div v-else>
<p :class="$style.loginMessage">{{ i18n.ts._auth.pleaseLogin }}</p>
<MkSignin @login="onLogin"/>
</div>
</MkSpacer>
</MkStickyContainer>
2020-03-28 02:24:37 +00:00
</template>
<script lang="ts" setup>
import { } from 'vue';
import MkSignin from '@/components/MkSignin.vue';
import MkButton from '@/components/MkButton.vue';
2021-11-11 17:02:25 +00:00
import * as os from '@/os';
import { $i, login } from '@/account';
import { i18n } from '@/i18n';
import { definePageMetadata } from '@/scripts/page-metadata';
const props = defineProps<{
session: string;
callback?: string;
name: string;
icon: string;
permission: string; // コンマ区切り
}>();
const _permissions = props.permission ? props.permission.split(',') : [];
let state = $ref<string | null>(null);
async function accept(): Promise<void> {
state = 'waiting';
await os.api('miauth/gen-token', {
session: props.session,
name: props.name,
iconUrl: props.icon,
permission: _permissions,
});
state = 'accepted';
if (props.callback) {
const cbUrl = new URL(props.callback);
if (['javascript:', 'file:', 'data:', 'mailto:', 'tel:'].includes(cbUrl.protocol)) throw new Error('invalid url');
cbUrl.searchParams.set('session', props.session);
location.href = cbUrl.href;
}
}
2020-03-28 02:24:37 +00:00
function deny(): void {
state = 'denied';
}
2020-03-28 02:24:37 +00:00
function onLogin(res): void {
login(res.i);
}
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata({
title: 'MiAuth',
icon: 'ti ti-apps',
});
2020-03-28 02:24:37 +00:00
</script>
<style lang="scss" module>
.buttons {
margin-top: 16px;
display: flex;
gap: 8px;
flex-wrap: wrap;
}
2020-03-28 02:24:37 +00:00
.loginMessage {
text-align: center;
margin: 8px 0 24px;
}
2020-03-28 02:24:37 +00:00
</style>