mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-29 21:37:34 -07:00
Implement Twitter Connect
This commit is contained in:
parent
b702b65cf6
commit
6721b6db27
4 changed files with 43 additions and 6 deletions
|
@ -65,7 +65,7 @@
|
||||||
"@types/websocket": "0.0.32",
|
"@types/websocket": "0.0.32",
|
||||||
"accesses": "1.2.0",
|
"accesses": "1.2.0",
|
||||||
"argv": "0.0.2",
|
"argv": "0.0.2",
|
||||||
"autwh": "0.0.0",
|
"autwh": "0.0.1",
|
||||||
"babel-core": "6.22.1",
|
"babel-core": "6.22.1",
|
||||||
"babel-polyfill": "6.20.0",
|
"babel-polyfill": "6.20.0",
|
||||||
"babel-preset-es2015": "6.22.0",
|
"babel-preset-es2015": "6.22.0",
|
||||||
|
|
|
@ -64,7 +64,10 @@ export default (
|
||||||
delete _user.password;
|
delete _user.password;
|
||||||
delete _user.token;
|
delete _user.token;
|
||||||
delete _user.username_lower;
|
delete _user.username_lower;
|
||||||
delete _user.twitter;
|
if (_user.twitter) {
|
||||||
|
delete _user.twitter.accessToken;
|
||||||
|
delete _user.twitter.accessTokenSecret;
|
||||||
|
}
|
||||||
|
|
||||||
// Visible via only the official client
|
// Visible via only the official client
|
||||||
if (!opts.includeSecrets) {
|
if (!opts.includeSecrets) {
|
||||||
|
|
|
@ -3,10 +3,18 @@ import * as express from 'express';
|
||||||
//const Twitter = require('twitter');
|
//const Twitter = require('twitter');
|
||||||
import autwh from 'autwh';
|
import autwh from 'autwh';
|
||||||
import redis from '../../db/redis';
|
import redis from '../../db/redis';
|
||||||
|
import User from '../models/user';
|
||||||
|
import serialize from '../serializers/user';
|
||||||
|
import event from '../event';
|
||||||
import config from '../../conf';
|
import config from '../../conf';
|
||||||
|
|
||||||
module.exports = (app: express.Application) => {
|
module.exports = (app: express.Application) => {
|
||||||
if (config.twitter == null) return;
|
if (config.twitter == null) {
|
||||||
|
app.get('/connect/twitter', (req, res) => {
|
||||||
|
res.send('現在Twitterへ接続できません');
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const twAuth = autwh({
|
const twAuth = autwh({
|
||||||
consumerKey: config.twitter.consumer_key,
|
consumerKey: config.twitter.consumer_key,
|
||||||
|
@ -24,9 +32,23 @@ module.exports = (app: express.Application) => {
|
||||||
app.get('/tw/cb', (req, res): any => {
|
app.get('/tw/cb', (req, res): any => {
|
||||||
if (res.locals.user == null) return res.send('plz signin');
|
if (res.locals.user == null) return res.send('plz signin');
|
||||||
redis.get(res.locals.user, async (_, ctx) => {
|
redis.get(res.locals.user, async (_, ctx) => {
|
||||||
const tokens = await twAuth.done(JSON.parse(ctx), req.query.oauth_verifier);
|
const result = await twAuth.done(JSON.parse(ctx), req.query.oauth_verifier);
|
||||||
console.log(tokens);
|
|
||||||
res.send('Authorized!');
|
const user = await User.findOneAndUpdate({
|
||||||
|
token: res.locals.user
|
||||||
|
}, {
|
||||||
|
$set: {
|
||||||
|
twitter: result
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send(`Twitter: @${result.screenName} を、Misskey: @${user.username} に接続しました!`);
|
||||||
|
|
||||||
|
// Publish i updated event
|
||||||
|
event(user._id, 'i_updated', await serialize(user, user, {
|
||||||
|
detail: true,
|
||||||
|
includeSecrets: true
|
||||||
|
}));
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<p class={ active: page == 'notification' } onmousedown={ setPage.bind(null, 'notification') }><i class="fa fa-fw fa-bell-o"></i>通知</p>
|
<p class={ active: page == 'notification' } onmousedown={ setPage.bind(null, 'notification') }><i class="fa fa-fw fa-bell-o"></i>通知</p>
|
||||||
<p class={ active: page == 'drive' } onmousedown={ setPage.bind(null, 'drive') }><i class="fa fa-fw fa-cloud"></i>ドライブ</p>
|
<p class={ active: page == 'drive' } onmousedown={ setPage.bind(null, 'drive') }><i class="fa fa-fw fa-cloud"></i>ドライブ</p>
|
||||||
<p class={ active: page == 'apps' } onmousedown={ setPage.bind(null, 'apps') }><i class="fa fa-fw fa-puzzle-piece"></i>アプリ</p>
|
<p class={ active: page == 'apps' } onmousedown={ setPage.bind(null, 'apps') }><i class="fa fa-fw fa-puzzle-piece"></i>アプリ</p>
|
||||||
|
<p class={ active: page == 'twitter' } onmousedown={ setPage.bind(null, 'twitter') }><i class="fa fa-fw fa-twitter"></i>Twitter</p>
|
||||||
<p class={ active: page == 'signin' } onmousedown={ setPage.bind(null, 'signin') }><i class="fa fa-fw fa-sign-in"></i>ログイン履歴</p>
|
<p class={ active: page == 'signin' } onmousedown={ setPage.bind(null, 'signin') }><i class="fa fa-fw fa-sign-in"></i>ログイン履歴</p>
|
||||||
<p class={ active: page == 'password' } onmousedown={ setPage.bind(null, 'password') }><i class="fa fa-fw fa-unlock-alt"></i>パスワード</p>
|
<p class={ active: page == 'password' } onmousedown={ setPage.bind(null, 'password') }><i class="fa fa-fw fa-unlock-alt"></i>パスワード</p>
|
||||||
<p class={ active: page == 'api' } onmousedown={ setPage.bind(null, 'api') }><i class="fa fa-fw fa-key"></i>API</p>
|
<p class={ active: page == 'api' } onmousedown={ setPage.bind(null, 'api') }><i class="fa fa-fw fa-key"></i>API</p>
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
</label>
|
</label>
|
||||||
<button class="style-primary" onclick={ updateAccount }>保存</button>
|
<button class="style-primary" onclick={ updateAccount }>保存</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="web" show={ page == 'web' }>
|
<section class="web" show={ page == 'web' }>
|
||||||
<h1>デザイン</h1>
|
<h1>デザイン</h1>
|
||||||
<label>
|
<label>
|
||||||
|
@ -41,6 +43,7 @@
|
||||||
<button class="style-normal" onclick={ wallpaper }>画像を選択</button>
|
<button class="style-normal" onclick={ wallpaper }>画像を選択</button>
|
||||||
</label>
|
</label>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="web" show={ page == 'web' }>
|
<section class="web" show={ page == 'web' }>
|
||||||
<h1>その他</h1>
|
<h1>その他</h1>
|
||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
|
@ -59,10 +62,19 @@
|
||||||
<p>攻撃的な投稿が多少和らぐ可能性があります。</p>
|
<p>攻撃的な投稿が多少和らぐ可能性があります。</p>
|
||||||
</label>
|
</label>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="twitter" show={ page == 'twitter' }>
|
||||||
|
<h1>Twitter</h1>
|
||||||
|
<p>お使いのTwitterアカウントをお使いのMisskeyアカウントに接続しておくと、プロフィールでTwitterアカウント情報が表示されるようになったり、Twitterを用いた便利なサインインを利用できるようにな<del>ります</del><strong>る予定です</strong>。</p>
|
||||||
|
<p if={ I.twitter }>アカウントは次のTwitterアカウントに接続されています: <strong>@{ I.twitter.screenName }</strong></p>
|
||||||
|
<a href={ CONFIG.api.url + '/connect/twitter' } target='_blank'>Twitterと接続する</a>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="signin" show={ page == 'signin' }>
|
<section class="signin" show={ page == 'signin' }>
|
||||||
<h1>ログイン履歴</h1>
|
<h1>ログイン履歴</h1>
|
||||||
<mk-signin-history></mk-signin-history>
|
<mk-signin-history></mk-signin-history>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="api" show={ page == 'api' }>
|
<section class="api" show={ page == 'api' }>
|
||||||
<h1>API</h1>
|
<h1>API</h1>
|
||||||
<p>Token:<code>{ I.token }</code></p>
|
<p>Token:<code>{ I.token }</code></p>
|
||||||
|
|
Loading…
Reference in a new issue