Skip to content

Commit

Permalink
認証の修正 (#1427)
Browse files Browse the repository at this point in the history
* 凍結ユーザーがサインイン出来てしまうのを修正

* 凍結ユーザーはストリーミング接続出来ないように

* トークン等が無効になったらストリーミングを切断するように

* signinでsuspendは別のエラーにする

* トークン再生成後のストリーミング切断は少し待つように
  • Loading branch information
mei23 authored Jul 17, 2021
1 parent 130201b commit de95b6e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/server/api/endpoints/admin/suspend-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Users, Followings, Notifications } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { insertModerationLog } from '../../../../services/insert-moderation-log';
import { doPostSuspend } from '../../../../services/suspend-user';
import { publishTerminate } from '../../../../services/server-event';

export const meta = {
desc: {
Expand Down Expand Up @@ -52,6 +53,10 @@ export default define(meta, async (ps, me) => {
targetId: user.id,
});

if (Users.isLocalUser(user)) {
publishTerminate(user.id);
}

(async () => {
await doPostSuspend(user).catch(e => {});
await unFollowAll(user).catch(e => {});
Expand Down
4 changes: 4 additions & 0 deletions src/server/api/endpoints/i/delete-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import define from '../../define';
import { Users, UserProfiles } from '../../../../models';
import { ensure } from '../../../../prelude/ensure';
import { doPostSuspend } from '../../../../services/suspend-user';
import { publishTerminate } from '../../../../services/server-event';

export const meta = {
requireCredential: true,
Expand Down Expand Up @@ -31,4 +32,7 @@ export default define(meta, async (ps, user) => {
await doPostSuspend(user).catch(e => {});

await Users.delete(user.id);

// Terminate streaming
publishTerminate(user.id);
});
6 changes: 6 additions & 0 deletions src/server/api/endpoints/i/regenerate-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import generateUserToken from '../../common/generate-native-user-token';
import define from '../../define';
import { Users, UserProfiles } from '../../../../models';
import { ensure } from '../../../../prelude/ensure';
import { publishTerminate } from '../../../../services/server-event';

export const meta = {
requireCredential: true,
Expand Down Expand Up @@ -37,4 +38,9 @@ export default define(meta, async (ps, user) => {

// Publish event
publishMainStream(user.id, 'myTokenRegenerated');

// Terminate streaming
setTimeout(() => {
publishTerminate(user.id);
}, 5000);
});
7 changes: 7 additions & 0 deletions src/server/api/private/signin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export default async (ctx: Koa.Context) => {
return;
}

if (user.isSuspended) {
ctx.throw(403, {
error: 'user is suspended'
});
return;
}

const profile = await UserProfiles.findOne(user.id).then(ensure);

// Compare password
Expand Down
5 changes: 5 additions & 0 deletions src/server/api/stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export default class Connection {
if (data.type === 'mutingChanged') {
this.updateMuting();
}

if (data.type === 'terminate') {
this.wsConnection.close();
this.dispose();
}
}

@autobind
Expand Down
5 changes: 5 additions & 0 deletions src/server/api/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ module.exports = (server: http.Server) => {
const q = request.resourceURL.query as ParsedUrlQuery;
const [user, app] = await authenticate(q.i as string);

if (user?.isSuspended) {
request.reject(400);
return;
}

const connection = request.accept();

let ev: EventEmitter;
Expand Down

0 comments on commit de95b6e

Please sign in to comment.