This commit is contained in:
syuilo
2018-04-02 04:01:34 +09:00
parent ad57e36d0d
commit e8bde94e5b
9 changed files with 47 additions and 40 deletions

View File

@ -1,8 +1,9 @@
import * as bodyParser from 'body-parser';
import * as express from 'express';
import { parseRequest, verifySignature } from 'http-signature';
import User, { IRemoteAccount } from '../../models/user';
import User, { IRemoteUser } from '../../models/user';
import queue from '../../queue';
import parseAcct from '../../common/user/parse-acct';
const app = express();
app.disable('x-powered-by');
@ -36,13 +37,13 @@ app.post('/@:user/inbox', async (req, res) => {
};
}
const user = await User.findOne(query);
const user = await User.findOne(query) as IRemoteUser;
if (user === null) {
return res.sendStatus(401);
}
if (!verifySignature(parsed, (user.account as IRemoteAccount).publicKey.publicKeyPem)) {
if (!verifySignature(parsed, user.account.publicKey.publicKeyPem)) {
return res.sendStatus(401);
}

View File

@ -1,7 +1,7 @@
import * as EventEmitter from 'events';
import * as bcrypt from 'bcryptjs';
import User, { ILocalAccount, IUser, init as initUser } from '../../../models/user';
import User, { IUser, init as initUser, ILocalUser } from '../../../models/user';
import getPostSummary from '../../../common/get-post-summary';
import getUserSummary from '../../../common/user/get-summary';
@ -198,7 +198,7 @@ abstract class Context extends EventEmitter {
}
class SigninContext extends Context {
private temporaryUser: IUser = null;
private temporaryUser: ILocalUser = null;
public async greet(): Promise<string> {
return 'まずユーザー名を教えてください:';
@ -207,14 +207,14 @@ class SigninContext extends Context {
public async q(query: string): Promise<string> {
if (this.temporaryUser == null) {
// Fetch user
const user: IUser = await User.findOne({
const user = await User.findOne({
usernameLower: query.toLowerCase(),
host: null
}, {
fields: {
data: false
}
});
}) as ILocalUser;
if (user === null) {
return `${query}というユーザーは存在しませんでした... もう一度教えてください:`;
@ -225,7 +225,7 @@ class SigninContext extends Context {
}
} else {
// Compare password
const same = await bcrypt.compare(query, (this.temporaryUser.account as ILocalAccount).password);
const same = await bcrypt.compare(query, this.temporaryUser.account.password);
if (same) {
this.bot.signin(this.temporaryUser);

View File

@ -5,9 +5,9 @@ import $ from 'cafy';
import deepEqual = require('deep-equal');
import html from '../../../../common/text/html';
import parse from '../../../../common/text/parse';
import { default as Post, IPost, isValidText, isValidCw } from '../../../../models/post';
import { default as User, ILocalAccount, IUser } from '../../../../models/user';
import { default as Channel, IChannel } from '../../../../models/channel';
import Post, { IPost, isValidText, isValidCw } from '../../../../models/post';
import User, { ILocalUser } from '../../../../models/user';
import Channel, { IChannel } from '../../../../models/channel';
import Following from '../../../../models/following';
import Mute from '../../../../models/mute';
import DriveFile from '../../../../models/drive-file';
@ -29,7 +29,7 @@ import config from '../../../../conf';
* @param {any} app
* @return {Promise<any>}
*/
module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
module.exports = (params, user: ILocalUser, app) => new Promise(async (res, rej) => {
// Get 'text' parameter
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text');
@ -400,7 +400,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
});
// この投稿をWatchする
if ((user.account as ILocalAccount).settings.autoWatch !== false) {
if (user.account.settings.autoWatch !== false) {
watch(user._id, reply);
}

View File

@ -1,7 +1,7 @@
import * as express from 'express';
import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy';
import { default as User, ILocalAccount, IUser } from '../../../models/user';
import User, { ILocalUser } from '../../../models/user';
import Signin, { pack } from '../../../models/signin';
import event from '../../../common/event';
import signin from '../common/signin';
@ -31,7 +31,7 @@ export default async (req: express.Request, res: express.Response) => {
}
// Fetch user
const user: IUser = await User.findOne({
const user = await User.findOne({
usernameLower: username.toLowerCase(),
host: null
}, {
@ -39,7 +39,7 @@ export default async (req: express.Request, res: express.Response) => {
data: false,
'account.profile': false
}
});
}) as ILocalUser;
if (user === null) {
res.status(404).send({
@ -48,7 +48,7 @@ export default async (req: express.Request, res: express.Response) => {
return;
}
const account = user.account as ILocalAccount;
const account = user.account;
// Compare password
const same = await bcrypt.compare(password, account.password);