1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-03 01:08:57 +09:00
This commit is contained in:
syuilo 2017-09-16 17:31:41 +09:00
commit 588f35a16a
4 changed files with 37 additions and 28 deletions

View File

@ -47,13 +47,13 @@
"@types/is-root": "1.0.0", "@types/is-root": "1.0.0",
"@types/is-url": "1.2.28", "@types/is-url": "1.2.28",
"@types/js-yaml": "3.9.0", "@types/js-yaml": "3.9.0",
"@types/mocha": "2.2.42", "@types/mocha": "2.2.43",
"@types/mongodb": "2.2.11", "@types/mongodb": "2.2.11",
"@types/monk": "1.0.6", "@types/monk": "1.0.6",
"@types/morgan": "1.7.32", "@types/morgan": "1.7.32",
"@types/ms": "0.7.30", "@types/ms": "0.7.30",
"@types/multer": "1.3.2", "@types/multer": "1.3.2",
"@types/node": "8.0.27", "@types/node": "8.0.28",
"@types/ratelimiter": "2.1.28", "@types/ratelimiter": "2.1.28",
"@types/redis": "2.6.0", "@types/redis": "2.6.0",
"@types/request": "2.0.3", "@types/request": "2.0.3",
@ -80,7 +80,7 @@
"gulp-typescript": "3.2.2", "gulp-typescript": "3.2.2",
"gulp-uglify": "3.0.0", "gulp-uglify": "3.0.0",
"gulp-util": "3.0.8", "gulp-util": "3.0.8",
"mocha": "3.5.0", "mocha": "3.5.3",
"riot-tag-loader": "1.0.0", "riot-tag-loader": "1.0.0",
"string-replace-webpack-plugin": "0.1.3", "string-replace-webpack-plugin": "0.1.3",
"style-loader": "0.18.2", "style-loader": "0.18.2",
@ -91,14 +91,14 @@
"uglify-es": "3.0.27", "uglify-es": "3.0.27",
"uglify-es-webpack-plugin": "0.10.0", "uglify-es-webpack-plugin": "0.10.0",
"uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony", "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony",
"webpack": "3.5.6" "webpack": "3.6.0"
}, },
"dependencies": { "dependencies": {
"accesses": "2.5.0", "accesses": "2.5.0",
"animejs": "2.0.2", "animejs": "2.0.2",
"autwh": "0.0.1", "autwh": "0.0.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"body-parser": "1.17.2", "body-parser": "1.18.1",
"cafy": "2.4.0", "cafy": "2.4.0",
"chalk": "2.1.0", "chalk": "2.1.0",
"compression": "1.7.0", "compression": "1.7.0",
@ -119,11 +119,11 @@
"inquirer": "3.2.3", "inquirer": "3.2.3",
"is-root": "1.0.0", "is-root": "1.0.0",
"is-url": "1.2.2", "is-url": "1.2.2",
"js-yaml": "3.9.1", "js-yaml": "3.10.0",
"mecab-async": "^0.1.0", "mecab-async": "^0.1.0",
"moji": "^0.5.1", "moji": "^0.5.1",
"mongodb": "2.2.31", "mongodb": "2.2.31",
"monk": "6.0.3", "monk": "6.0.4",
"morgan": "1.8.2", "morgan": "1.8.2",
"ms": "2.0.0", "ms": "2.0.0",
"multer": "1.3.0", "multer": "1.3.0",
@ -138,11 +138,11 @@
"reconnecting-websocket": "3.2.1", "reconnecting-websocket": "3.2.1",
"redis": "2.8.0", "redis": "2.8.0",
"request": "2.81.0", "request": "2.81.0",
"rimraf": "2.6.1", "rimraf": "2.6.2",
"riot": "3.7.0", "riot": "3.7.0",
"rndstr": "1.0.0", "rndstr": "1.0.0",
"s-age": "1.1.0", "s-age": "1.1.0",
"serve-favicon": "2.4.3", "serve-favicon": "2.4.4",
"summaly": "2.0.3", "summaly": "2.0.3",
"syuilo-password-strength": "0.0.1", "syuilo-password-strength": "0.0.1",
"tcp-port-used": "0.1.2", "tcp-port-used": "0.1.2",

View File

@ -1,6 +1,6 @@
import * as express from 'express'; import * as express from 'express';
import App from './models/app'; import App from './models/app';
import User from './models/user'; import { default as User, IUser } from './models/user';
import AccessToken from './models/access-token'; import AccessToken from './models/access-token';
import isNativeToken from './common/is-native-token'; import isNativeToken from './common/is-native-token';
@ -13,10 +13,10 @@ export interface IAuthContext {
/** /**
* Authenticated user * Authenticated user
*/ */
user: any; user: IUser;
/** /**
* Weather if the request is via the User-Native Token or not * Whether requested with a User-Native Token
*/ */
isSecure: boolean; isSecure: boolean;
} }
@ -25,11 +25,15 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
const token = req.body['i'] as string; const token = req.body['i'] as string;
if (token == null) { if (token == null) {
return resolve({ app: null, user: null, isSecure: false }); return resolve({
app: null,
user: null,
isSecure: false
});
} }
if (isNativeToken(token)) { if (isNativeToken(token)) {
const user = await User const user: IUser = await User
.findOne({ token: token }); .findOne({ token: token });
if (user === null) { if (user === null) {
@ -56,6 +60,10 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
const user = await User const user = await User
.findOne({ _id: accessToken.user_id }); .findOne({ _id: accessToken.user_id });
return resolve({ app: app, user: user, isSecure: false }); return resolve({
app: app,
user: user,
isSecure: false
});
} }
}); });

View File

@ -37,7 +37,9 @@ export default (
data: false data: false
} : { } : {
data: false, data: false,
profile: false profile: false,
keywords: false,
domains: false
}; };
// Populate the user if 'user' is ID // Populate the user if 'user' is ID
@ -119,6 +121,7 @@ export default (
if (opts.detail) { if (opts.detail) {
if (_user.pinned_post_id) { if (_user.pinned_post_id) {
// Populate pinned post
_user.pinned_post = await serializePost(_user.pinned_post_id, meId, { _user.pinned_post = await serializePost(_user.pinned_post_id, meId, {
detail: true detail: true
}); });

View File

@ -2,7 +2,7 @@ import * as http from 'http';
import * as websocket from 'websocket'; import * as websocket from 'websocket';
import * as redis from 'redis'; import * as redis from 'redis';
import config from '../conf'; import config from '../conf';
import User from './models/user'; import { default as User, IUser } from './models/user';
import AccessToken from './models/access-token'; import AccessToken from './models/access-token';
import isNativeToken from './common/is-native-token'; import isNativeToken from './common/is-native-token';
@ -26,7 +26,7 @@ module.exports = (server: http.Server) => {
return; return;
} }
const user = await authenticate(connection, request.resourceURL.query.i); const user = await authenticate(request.resourceURL.query.i);
if (user == null) { if (user == null) {
connection.send('authentication-failed'); connection.send('authentication-failed');
@ -56,7 +56,11 @@ module.exports = (server: http.Server) => {
}); });
}; };
function authenticate(connection: websocket.connection, token: string): Promise<any> { /**
*
* @param token
*/
function authenticate(token: string): Promise<IUser> {
if (token == null) { if (token == null) {
return Promise.resolve(null); return Promise.resolve(null);
} }
@ -64,8 +68,7 @@ function authenticate(connection: websocket.connection, token: string): Promise<
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
if (isNativeToken(token)) { if (isNativeToken(token)) {
// Fetch user // Fetch user
// SELECT _id const user: IUser = await User
const user = await User
.findOne({ .findOne({
token: token token: token
}); });
@ -81,13 +84,8 @@ function authenticate(connection: websocket.connection, token: string): Promise<
} }
// Fetch user // Fetch user
// SELECT _id const user: IUser = await User
const user = await User .findOne({ _id: accessToken.user_id });
.findOne({ _id: accessToken.user_id }, {
fields: {
_id: true
}
});
resolve(user); resolve(user);
} }