From 2a1fab34df0ae5a6e8bdaf5cd731ae50545328b6 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 22 Feb 2017 01:05:23 +0900 Subject: wip --- src/web/app/auth/tags/form.tag | 12 +++++--- src/web/app/auth/tags/index.tag | 66 ++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 32 deletions(-) (limited to 'src/web/app/auth') diff --git a/src/web/app/auth/tags/form.tag b/src/web/app/auth/tags/form.tag index 619c71065e..4a236f7594 100644 --- a/src/web/app/auth/tags/form.tag +++ b/src/web/app/auth/tags/form.tag @@ -108,19 +108,23 @@ diff --git a/src/web/app/auth/tags/index.tag b/src/web/app/auth/tags/index.tag index e52aeed4d2..f80e9dd1bc 100644 --- a/src/web/app/auth/tags/index.tag +++ b/src/web/app/auth/tags/index.tag @@ -91,47 +91,57 @@ this.mixin('i'); this.mixin('api'); - this.state = null - this.fetching = true + this.state = null; + this.fetching = true; - this.token = window.location.href.split '/' .pop! + this.token = window.location.href.split('/').pop(); this.on('mount', () => { - if not this.SIGNIN then return + if (!this.SIGNIN) return; // Fetch session this.api('auth/session/show', { - token: @token - }).then((session) => { - this.session = session - this.fetching = false + token: this.token + }).then(session => { + this.session = session; + this.fetching = false; // 既に連携していた場合 - if @session.app.is_authorized + if (this.session.app.is_authorized) { this.api('auth/accept', { - token: @session.token + token: this.session.token }).then(() => { - @accepted! - else - this.state = 'waiting' - this.update(); + this.accepted(); + }); + } else { + this.update({ + state: 'waiting' + }); this.refs.form.on('denied', () => { - this.state = 'denied' - this.update(); - - this.refs.form.on 'accepted' @accepted - - .catch (error) => - this.fetching = false - this.state = 'fetch-session-error' - this.update(); + this.update({ + state: 'denied' + }); + }); + + this.refs.form.on('accepted', this.accepted); + } + }).catch(error => { + this.update({ + fetching: false, + state: 'fetch-session-error' + }); + }); + }); this.accepted = () => { - this.state = 'accepted' - this.update(); - - if @session.app.callback_url - location.href = @session.app.callback_url + '?token=' + @session.token + this.update({ + state: 'accepted' + }); + + if (this.session.app.callback_url) { + location.href = this.session.app.callback_url + '?token=' + this.session.token; + } + }; -- cgit v1.2.3-freya