2018-02-20 11:50:01 +00:00
|
|
|
<template>
|
|
|
|
<div class="index">
|
2018-05-27 04:49:09 +00:00
|
|
|
<main v-if="$store.getters.isSignedIn">
|
2018-11-08 18:44:35 +00:00
|
|
|
<p class="fetching" v-if="fetching">{{ $t('loading') }}<mk-ellipsis/></p>
|
2018-02-20 16:39:51 +00:00
|
|
|
<x-form
|
2018-06-02 19:51:58 +00:00
|
|
|
class="form"
|
2018-02-20 11:50:01 +00:00
|
|
|
ref="form"
|
|
|
|
v-if="state == 'waiting'"
|
|
|
|
:session="session"
|
|
|
|
@denied="state = 'denied'"
|
|
|
|
@accepted="accepted"
|
|
|
|
/>
|
|
|
|
<div class="denied" v-if="state == 'denied'">
|
2018-11-08 18:44:35 +00:00
|
|
|
<h1>{{ $t('denied') }}</h1>
|
|
|
|
<p>{{ $t('denied-paragraph') }}</p>
|
2018-02-20 11:50:01 +00:00
|
|
|
</div>
|
|
|
|
<div class="accepted" v-if="state == 'accepted'">
|
2018-11-08 18:44:35 +00:00
|
|
|
<h1>{{ session.app.isAuthorized ? this.$t('already-authorized') : this.$t('allowed') }}</h1>
|
|
|
|
<p v-if="session.app.callbackUrl">{{ $t('callback-url') }}<mk-ellipsis/></p>
|
|
|
|
<p v-if="!session.app.callbackUrl">{{ $t('please-go-back') }}</p>
|
2018-02-20 11:50:01 +00:00
|
|
|
</div>
|
|
|
|
<div class="error" v-if="state == 'fetch-session-error'">
|
2018-11-08 18:44:35 +00:00
|
|
|
<p>{{ $t('error') }}</p>
|
2018-02-20 11:50:01 +00:00
|
|
|
</div>
|
|
|
|
</main>
|
2018-05-27 04:49:09 +00:00
|
|
|
<main class="signin" v-if="!$store.getters.isSignedIn">
|
2018-11-08 18:44:35 +00:00
|
|
|
<h1>{{ $t('sign-in') }}</h1>
|
2018-02-20 11:50:01 +00:00
|
|
|
<mk-signin/>
|
|
|
|
</main>
|
2018-06-02 22:34:34 +00:00
|
|
|
<footer><img src="/assets/auth/icon.svg" alt="Misskey"/></footer>
|
2018-02-20 11:50:01 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-08 18:44:35 +00:00
|
|
|
import i18n from '../../i18n';
|
2018-02-20 16:39:51 +00:00
|
|
|
import XForm from './form.vue';
|
2018-02-20 11:50:01 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-11-08 18:44:35 +00:00
|
|
|
i18n: i18n('auth/views/index.vue'),
|
2018-02-20 11:50:01 +00:00
|
|
|
components: {
|
2018-02-20 16:39:51 +00:00
|
|
|
XForm
|
2018-02-20 11:50:01 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
state: null,
|
|
|
|
session: null,
|
2018-02-27 15:11:28 +00:00
|
|
|
fetching: true
|
2018-02-20 11:50:01 +00:00
|
|
|
};
|
|
|
|
},
|
2018-02-27 15:11:28 +00:00
|
|
|
computed: {
|
|
|
|
token(): string {
|
|
|
|
return this.$route.params.token;
|
|
|
|
}
|
|
|
|
},
|
2018-02-20 11:50:01 +00:00
|
|
|
mounted() {
|
2018-05-28 16:55:32 +00:00
|
|
|
if (!this.$store.getters.isSignedIn) return;
|
2018-02-20 11:50:01 +00:00
|
|
|
|
|
|
|
// Fetch session
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('auth/session/show', {
|
2018-02-20 11:50:01 +00:00
|
|
|
token: this.token
|
|
|
|
}).then(session => {
|
|
|
|
this.session = session;
|
|
|
|
this.fetching = false;
|
|
|
|
|
|
|
|
// 既に連携していた場合
|
2018-03-29 05:48:47 +00:00
|
|
|
if (this.session.app.isAuthorized) {
|
2018-11-08 23:13:34 +00:00
|
|
|
this.$root.api('auth/accept', {
|
2018-02-20 11:50:01 +00:00
|
|
|
token: this.session.token
|
|
|
|
}).then(() => {
|
|
|
|
this.accepted();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.state = 'waiting';
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
this.state = 'fetch-session-error';
|
2018-05-28 16:55:32 +00:00
|
|
|
this.fetching = false;
|
2018-02-20 11:50:01 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
accepted() {
|
|
|
|
this.state = 'accepted';
|
2018-03-29 05:48:47 +00:00
|
|
|
if (this.session.app.callbackUrl) {
|
2018-09-01 14:12:51 +00:00
|
|
|
location.href = `${this.session.app.callbackUrl}?token=${this.session.token}`;
|
2018-02-20 11:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.index
|
|
|
|
|
|
|
|
> main
|
|
|
|
width 100%
|
|
|
|
max-width 500px
|
|
|
|
margin 0 auto
|
|
|
|
text-align center
|
|
|
|
background #fff
|
2018-04-28 23:51:17 +00:00
|
|
|
box-shadow 0px 4px 16px rgba(#000, 0.2)
|
2018-02-20 11:50:01 +00:00
|
|
|
|
|
|
|
> .fetching
|
|
|
|
margin 0
|
|
|
|
padding 32px
|
|
|
|
color #555
|
|
|
|
|
2018-06-02 19:51:58 +00:00
|
|
|
> div:not(.form)
|
2018-02-20 11:50:01 +00:00
|
|
|
padding 64px
|
|
|
|
|
|
|
|
> h1
|
|
|
|
margin 0 0 8px 0
|
|
|
|
padding 0
|
|
|
|
font-size 20px
|
|
|
|
font-weight normal
|
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
|
|
|
color #555
|
|
|
|
|
|
|
|
&.denied > h1
|
|
|
|
color #e65050
|
|
|
|
|
|
|
|
&.accepted > h1
|
|
|
|
color #54af7c
|
|
|
|
|
|
|
|
&.signin
|
|
|
|
padding 32px 32px 16px 32px
|
|
|
|
|
|
|
|
> h1
|
|
|
|
margin 0 0 22px 0
|
|
|
|
padding 0
|
|
|
|
font-size 20px
|
|
|
|
font-weight normal
|
|
|
|
color #555
|
|
|
|
|
|
|
|
@media (max-width 600px)
|
|
|
|
max-width none
|
|
|
|
box-shadow none
|
|
|
|
|
|
|
|
@media (max-width 500px)
|
|
|
|
> div
|
|
|
|
> h1
|
|
|
|
font-size 16px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
> img
|
|
|
|
display block
|
2018-06-02 22:34:34 +00:00
|
|
|
width 32px
|
|
|
|
height 32px
|
|
|
|
margin 16px auto
|
2018-02-20 11:50:01 +00:00
|
|
|
|
|
|
|
</style>
|