Sharkey/src/client/pages/miauth.vue

102 lines
2.3 KiB
Vue
Raw Normal View History

2020-03-27 19:24:37 -07:00
<template>
<div v-if="$store.getters.isSignedIn">
<div class="waiting _card _vMargin" v-if="state == 'waiting'">
2020-03-27 19:24:37 -07:00
<div class="_content">
<mk-loading/>
</div>
</div>
<div class="denied _card _vMargin" v-if="state == 'denied'">
2020-03-27 19:24:37 -07:00
<div class="_content">
<p>{{ $t('_auth.denied') }}</p>
2020-03-27 19:24:37 -07:00
</div>
</div>
<div class="accepted _card _vMargin" v-else-if="state == 'accepted'">
2020-03-27 19:24:37 -07:00
<div class="_content">
<p v-if="callback">{{ $t('_auth.callback') }}<mk-ellipsis/></p>
<p v-else>{{ $t('_auth.pleaseGoBack') }}</p>
</div>
</div>
<div class="_card _vMargin" v-else>
2020-03-27 19:24:37 -07:00
<div class="_title" v-if="name">{{ $t('_auth.shareAccess', { name: name }) }}</div>
<div class="_title" v-else>{{ $t('_auth.shareAccessAsk') }}</div>
<div class="_content">
<p>{{ $t('_auth.permissionAsk') }}</p>
2020-03-27 19:24:37 -07:00
<ul>
<template v-for="p in permission">
<li :key="p">{{ $t(`_permissions.${p}`) }}</li>
</template>
</ul>
</div>
<div class="_footer">
<mk-button @click="deny" inline>{{ $t('cancel') }}</mk-button>
<mk-button @click="accept" inline primary>{{ $t('accept') }}</mk-button>
</div>
</div>
</div>
<div class="signin" v-else>
<mk-signin @login="onLogin"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import MkSignin from '../components/signin.vue';
import MkButton from '../components/ui/button.vue';
export default Vue.extend({
components: {
MkSignin,
MkButton,
},
data() {
return {
state: null
};
},
computed: {
session(): string {
return this.$route.params.session;
},
callback(): string {
return this.$route.query.callback;
},
name(): string {
return this.$route.query.name;
},
2020-03-28 02:33:24 -07:00
icon(): string {
return this.$route.query.icon;
},
2020-03-29 01:04:22 -07:00
permission(): string[] {
return this.$route.query.permission ? this.$route.query.permission.split(',') : [];
2020-03-27 19:24:37 -07:00
},
},
methods: {
async accept() {
this.state = 'waiting';
await this.$root.api('miauth/gen-token', {
session: this.session,
name: this.name,
2020-03-28 02:33:24 -07:00
iconUrl: this.icon,
2020-03-29 01:04:22 -07:00
permission: this.permission,
2020-03-27 19:24:37 -07:00
});
this.state = 'accepted';
if (this.callback) {
location.href = `${this.callback}?session=${this.session}`;
}
},
deny() {
this.state = 'denied';
},
onLogin(res) {
localStorage.setItem('i', res.i);
location.reload();
}
}
});
</script>
<style lang="scss" scoped>
</style>