2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
|
|
|
<div class="_panel" v-if="$store.getters.isSignedIn && fetching">
|
|
|
|
<mk-loading/>
|
|
|
|
</div>
|
|
|
|
<div v-else-if="$store.getters.isSignedIn">
|
|
|
|
<x-form
|
|
|
|
class="form"
|
|
|
|
ref="form"
|
|
|
|
v-if="state == 'waiting'"
|
|
|
|
:session="session"
|
|
|
|
@denied="state = 'denied'"
|
|
|
|
@accepted="accepted"
|
|
|
|
/>
|
|
|
|
<div class="denied _panel" v-if="state == 'denied'">
|
2020-03-28 04:24:37 +02:00
|
|
|
<h1>{{ $t('_auth.denied') }}</h1>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
<div class="accepted _panel" v-if="state == 'accepted'">
|
|
|
|
<h1>{{ session.app.isAuthorized ? this.$t('already-authorized') : this.$t('allowed') }}</h1>
|
2020-03-28 04:24:37 +02:00
|
|
|
<p v-if="session.app.callbackUrl">{{ $t('_auth.callback') }}<mk-ellipsis/></p>
|
2020-07-24 19:36:39 +03:00
|
|
|
<p v-if="!session.app.callbackUrl" v-t="'_auth.pleaseGoBack'"></p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
<div class="error _panel" v-if="state == 'fetch-session-error'">
|
2020-07-24 19:36:39 +03:00
|
|
|
<p v-t="'error'"></p>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="signin" v-else>
|
2020-03-14 08:59:02 +02:00
|
|
|
<mk-signin @login="onLogin"/>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import XForm from './auth.form.vue';
|
2020-02-20 16:07:20 +02:00
|
|
|
import MkSignin from '../components/signin.vue';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
components: {
|
2020-02-20 16:07:20 +02:00
|
|
|
XForm,
|
|
|
|
MkSignin,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
state: null,
|
|
|
|
session: null,
|
|
|
|
fetching: true
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
token(): string {
|
|
|
|
return this.$route.params.token;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (!this.$store.getters.isSignedIn) return;
|
|
|
|
|
|
|
|
// Fetch session
|
|
|
|
this.$root.api('auth/session/show', {
|
|
|
|
token: this.token
|
|
|
|
}).then(session => {
|
|
|
|
this.session = session;
|
|
|
|
this.fetching = false;
|
|
|
|
|
|
|
|
// 既に連携していた場合
|
|
|
|
if (this.session.app.isAuthorized) {
|
|
|
|
this.$root.api('auth/accept', {
|
|
|
|
token: this.session.token
|
|
|
|
}).then(() => {
|
|
|
|
this.accepted();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.state = 'waiting';
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
this.state = 'fetch-session-error';
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
accepted() {
|
|
|
|
this.state = 'accepted';
|
|
|
|
if (this.session.app.callbackUrl) {
|
|
|
|
location.href = `${this.session.app.callbackUrl}?token=${this.session.token}`;
|
|
|
|
}
|
2020-03-14 08:59:02 +02:00
|
|
|
}, onLogin(res) {
|
|
|
|
localStorage.setItem('i', res.i);
|
|
|
|
location.reload();
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|