diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts index ad45f42bc..e4abc06f5 100644 --- a/src/api/endpoints.ts +++ b/src/api/endpoints.ts @@ -46,6 +46,7 @@ export default [ { name: 'i/appdata/get', shouldBeSignin: true }, { name: 'i/appdata/set', shouldBeSignin: true }, { name: 'i/signin_history', shouldBeSignin: true, kind: 'account-read' }, + { name: 'i/authorized_apps', shouldBeSignin: true, secure: true }, { name: 'i/notifications', shouldBeSignin: true, kind: 'notification-read' }, { name: 'notifications/delete', shouldBeSignin: true, kind: 'notification-write' }, diff --git a/src/api/endpoints/i/authorized_apps.js b/src/api/endpoints/i/authorized_apps.js new file mode 100644 index 000000000..17f971af2 --- /dev/null +++ b/src/api/endpoints/i/authorized_apps.js @@ -0,0 +1,60 @@ +'use strict'; + +/** + * Module dependencies + */ +import * as mongo from 'mongodb'; +import AccessToken from '../../models/access-token'; +import App from '../../models/app'; +import serialize from '../../serializers/app'; + +/** + * Get authorized apps of my account + * + * @param {Object} params + * @param {Object} user + * @return {Promise} + */ +module.exports = (params, user) => + new Promise(async (res, rej) => +{ + // Get 'limit' parameter + let limit = params.limit; + if (limit !== undefined && limit !== null) { + limit = parseInt(limit, 10); + + // From 1 to 100 + if (!(1 <= limit && limit <= 100)) { + return rej('invalid limit range'); + } + } else { + limit = 10; + } + + // Get 'offset' parameter + let offset = params.offset; + if (offset !== undefined && offset !== null) { + offset = parseInt(offset, 10); + } else { + offset = 0; + } + + // Get 'sort' parameter + let sort = params.sort || 'desc'; + + // Get tokens + const tokens = await AccessToken + .find({ + user_id: user._id + }, { + limit: limit, + skip: offset, + sort: { + _id: sort == 'asc' ? 1 : -1 + } + }); + + // Serialize + res(await Promise.all(tokens.map(async token => + await serialize(token.app_id)))); +}); diff --git a/src/web/app/common/tags/authorized-apps.tag b/src/web/app/common/tags/authorized-apps.tag new file mode 100644 index 000000000..aedfc78fd --- /dev/null +++ b/src/web/app/common/tags/authorized-apps.tag @@ -0,0 +1,34 @@ + +

連携しているアプリケーションはありません。

+
+
+

{ app.name }

+

{ app.description }

+
+
+ + +
diff --git a/src/web/app/common/tags/index.js b/src/web/app/common/tags/index.js index a27dc1198..ef61d51ba 100644 --- a/src/web/app/common/tags/index.js +++ b/src/web/app/common/tags/index.js @@ -17,3 +17,4 @@ require('./copyright.tag'); require('./signin-history.tag'); require('./api-info.tag'); require('./twitter-setting.tag'); +require('./authorized-apps.tag'); diff --git a/src/web/app/desktop/tags/settings.tag b/src/web/app/desktop/tags/settings.tag index f446440dc..3f8f759b4 100644 --- a/src/web/app/desktop/tags/settings.tag +++ b/src/web/app/desktop/tags/settings.tag @@ -63,6 +63,11 @@ +
+

アプリケーション

+ +
+

Twitter

diff --git a/src/web/app/mobile/router.ls b/src/web/app/mobile/router.ls index 500f19e9a..ae68f2177 100644 --- a/src/web/app/mobile/router.ls +++ b/src/web/app/mobile/router.ls @@ -19,6 +19,7 @@ module.exports = (me) ~> route \/i/settings/signin-history settings-signin route \/i/settings/api settings-api route \/i/settings/twitter settings-twitter + route \/i/settings/authorized-apps settings-authorized-apps route \/post/new new-post route \/post::post post route \/search::query search @@ -61,6 +62,8 @@ module.exports = (me) ~> mount document.create-element \mk-api-info-page function settings-twitter mount document.create-element \mk-twitter-setting-page + function settings-authorized-apps + mount document.create-element \mk-authorized-apps-page # 検索 function search ctx diff --git a/src/web/app/mobile/tags/index.js b/src/web/app/mobile/tags/index.js index eb0f10cf7..a4374d4e1 100644 --- a/src/web/app/mobile/tags/index.js +++ b/src/web/app/mobile/tags/index.js @@ -17,6 +17,7 @@ require('./page/search.tag'); require('./page/settings.tag'); require('./page/settings/signin.tag'); require('./page/settings/api.tag'); +require('./page/settings/authorized-apps.tag'); require('./page/settings/twitter.tag'); require('./home.tag'); require('./home-timeline.tag'); diff --git a/src/web/app/mobile/tags/page/settings.tag b/src/web/app/mobile/tags/page/settings.tag index 77bf36dbb..18f03b303 100644 --- a/src/web/app/mobile/tags/page/settings.tag +++ b/src/web/app/mobile/tags/page/settings.tag @@ -2,6 +2,7 @@
  • プロフィール
  • +
  • アプリケーション
  • Twitter連携
  • ログイン履歴
  • API
  • diff --git a/src/web/app/mobile/tags/page/settings/authorized-apps.tag b/src/web/app/mobile/tags/page/settings/authorized-apps.tag new file mode 100644 index 000000000..a1385c493 --- /dev/null +++ b/src/web/app/mobile/tags/page/settings/authorized-apps.tag @@ -0,0 +1,16 @@ + + + + + + +