Refactor
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo