テーブル分割

This commit is contained in:
syuilo
2019-04-10 15:04:27 +09:00
parent 9603f3fa4f
commit 626cfb61ac
33 changed files with 267 additions and 232 deletions

View File

@ -3,7 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import * as bcrypt from 'bcryptjs';
import rndstr from 'rndstr';
import { Users } from '../../../../models';
import { Users, UserProfiles } from '../../../../models';
export const meta = {
desc: {
@ -42,7 +42,9 @@ export default define(meta, async (ps) => {
// Generate hash of password
const hash = bcrypt.hashSync(passwd);
await Users.update(user.id, {
await UserProfiles.update({
userId: user.id
}, {
password: hash
});

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import * as speakeasy from 'speakeasy';
import define from '../../../define';
import { Users } from '../../../../../models';
import { UserProfiles } from '../../../../../models';
export const meta = {
requireCredential: true,
@ -16,24 +16,26 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const _token = ps.token.replace(/\s/g, '');
const token = ps.token.replace(/\s/g, '');
if (user.twoFactorTempSecret == null) {
const profile = await UserProfiles.findOne({ userId: user.id });
if (profile.twoFactorTempSecret == null) {
throw new Error('二段階認証の設定が開始されていません');
}
const verified = (speakeasy as any).totp.verify({
secret: user.twoFactorTempSecret,
secret: profile.twoFactorTempSecret,
encoding: 'base32',
token: _token
token: token
});
if (!verified) {
throw new Error('not verified');
}
await Users.update(user.id, {
twoFactorSecret: user.twoFactorTempSecret,
await UserProfiles.update({ userId: user.id }, {
twoFactorSecret: profile.twoFactorTempSecret,
twoFactorEnabled: true
});
});

View File

@ -4,7 +4,7 @@ import * as speakeasy from 'speakeasy';
import * as QRCode from 'qrcode';
import config from '../../../../../config';
import define from '../../../define';
import { Users } from '../../../../../models';
import { UserProfiles } from '../../../../../models';
export const meta = {
requireCredential: true,
@ -19,8 +19,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
const same = await bcrypt.compare(ps.password, profile.password);
if (!same) {
throw new Error('incorrect password');
@ -31,7 +33,7 @@ export default define(meta, async (ps, user) => {
length: 32
});
await Users.update(user.id, {
await UserProfiles.update({ userId: user.id }, {
twoFactorTempSecret: secret.base32
});

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../../define';
import { Users } from '../../../../../models';
import { UserProfiles } from '../../../../../models';
export const meta = {
requireCredential: true,
@ -16,17 +16,17 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
const same = await bcrypt.compare(ps.password, profile.password);
if (!same) {
throw new Error('incorrect password');
}
await Users.update(user.id, {
await UserProfiles.update({ userId: user.id }, {
twoFactorSecret: null,
twoFactorEnabled: false
});
return;
});

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../define';
import { Users } from '../../../../models';
import { UserProfiles } from '../../../../models';
export const meta = {
requireCredential: true,
@ -20,8 +20,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.currentPassword, user.password);
const same = await bcrypt.compare(ps.currentPassword, profile.password);
if (!same) {
throw new Error('incorrect password');
@ -31,7 +33,7 @@ export default define(meta, async (ps, user) => {
const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash(ps.newPassword, salt);
await Users.update(user.id, {
await UserProfiles.update({ userId: user.id }, {
password: hash
});
});

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import * as bcrypt from 'bcryptjs';
import define from '../../define';
import { Users } from '../../../../models';
import { Users, UserProfiles } from '../../../../models';
export const meta = {
requireCredential: true,
@ -16,8 +16,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
const same = await bcrypt.compare(ps.password, profile.password);
if (!same) {
throw new Error('incorrect password');

View File

@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
import { publishMainStream } from '../../../../services/stream';
import generateUserToken from '../../common/generate-native-user-token';
import define from '../../define';
import { Users } from '../../../../models';
import { Users, UserProfiles } from '../../../../models';
export const meta = {
requireCredential: true,
@ -18,8 +18,10 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
const same = await bcrypt.compare(ps.password, profile.password);
if (!same) {
throw new Error('incorrect password');

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import { publishMainStream } from '../../../../services/stream';
import define from '../../define';
import { Users } from '../../../../models';
import { UserProfiles } from '../../../../models';
export const meta = {
requireCredential: true,
@ -20,7 +20,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
await Users.createQueryBuilder().update()
await UserProfiles.createQueryBuilder().update()
.set({
clientData: {
[ps.name]: ps.value

View File

@ -8,7 +8,7 @@ import config from '../../../../config';
import * as ms from 'ms';
import * as bcrypt from 'bcryptjs';
import { apiLogger } from '../../logger';
import { Users } from '../../../../models';
import { Users, UserProfiles } from '../../../../models';
export const meta = {
requireCredential: true,
@ -32,14 +32,16 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const profile = await UserProfiles.findOne({ userId: user.id });
// Compare password
const same = await bcrypt.compare(ps.password, user.password);
const same = await bcrypt.compare(ps.password, profile.password);
if (!same) {
throw new Error('incorrect password');
}
await Users.update(user.id, {
await UserProfiles.update({ userId: user.id }, {
email: ps.email,
emailVerified: false,
emailVerifyCode: null
@ -56,7 +58,7 @@ export default define(meta, async (ps, user) => {
if (ps.email != null) {
const code = rndstr('a-z0-9', 16);
await Users.update(user.id, {
await UserProfiles.update({ userId: user.id }, {
emailVerifyCode: code
});

View File

@ -10,7 +10,9 @@ import extractHashtags from '../../../../misc/extract-hashtags';
import * as langmap from 'langmap';
import { updateHashtag } from '../../../../services/update-hashtag';
import { ApiError } from '../../error';
import { Users, DriveFiles } from '../../../../models';
import { Users, DriveFiles, UserProfiles } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { UserProfile } from '../../../../models/entities/user-profile';
export const meta = {
desc: {
@ -154,22 +156,23 @@ export const meta = {
export default define(meta, async (ps, user, app) => {
const isSecure = user != null && app == null;
const updates = {} as any;
const updates = {} as Partial<User>;
const profile = {} as Partial<UserProfile>;
if (ps.name !== undefined) updates.name = ps.name;
if (ps.description !== undefined) updates.description = ps.description;
if (ps.lang !== undefined) updates.lang = ps.lang;
if (ps.location !== undefined) updates.location = ps.location;
if (ps.birthday !== undefined) updates.birthday = ps.birthday;
if (ps.description !== undefined) profile.description = ps.description;
//if (ps.lang !== undefined) updates.lang = ps.lang;
if (ps.location !== undefined) profile.location = ps.location;
if (ps.birthday !== undefined) profile.birthday = ps.birthday;
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
if (typeof ps.isLocked == 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot == 'boolean') updates.isBot = ps.isBot;
if (typeof ps.carefulBot == 'boolean') updates.carefulBot = ps.carefulBot;
if (typeof ps.autoAcceptFollowed == 'boolean') updates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.carefulBot == 'boolean') profile.carefulBot = ps.carefulBot;
if (typeof ps.autoAcceptFollowed == 'boolean') profile.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
if (typeof ps.autoWatch == 'boolean') updates.autoWatch = ps.autoWatch;
if (typeof ps.alwaysMarkNsfw == 'boolean') updates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
if (typeof ps.autoWatch == 'boolean') profile.autoWatch = ps.autoWatch;
if (typeof ps.alwaysMarkNsfw == 'boolean') profile.alwaysMarkNsfw = ps.alwaysMarkNsfw;
if (ps.avatarId) {
const avatar = await DriveFiles.findOne(ps.avatarId);
@ -206,8 +209,8 @@ export default define(meta, async (ps, user, app) => {
emojis = emojis.concat(extractEmojis(tokens));
}
if (updates.description != null) {
const tokens = parse(updates.description);
if (profile.description != null) {
const tokens = parse(profile.description);
emojis = emojis.concat(extractEmojis(tokens));
tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
}
@ -221,6 +224,7 @@ export default define(meta, async (ps, user, app) => {
//#endregion
await Users.update(user.id, updates);
await UserProfiles.update({ userId: user.id }, profile);
const iObj = await Users.pack(user.id, user, {
detail: true,

View File

@ -10,7 +10,7 @@ import { deliver } from '../../../../../queue';
import { renderActivity } from '../../../../../remote/activitypub/renderer';
import renderVote from '../../../../../remote/activitypub/renderer/vote';
import { deliverQuestionUpdate } from '../../../../../services/note/polls/update';
import { PollVotes, NoteWatchings, Users, Polls } from '../../../../../models';
import { PollVotes, NoteWatchings, Users, Polls, UserProfiles } from '../../../../../models';
import { Not } from 'typeorm';
import { IRemoteUser } from '../../../../../models/entities/user';
import { genId } from '../../../../../misc/gen-id';
@ -149,8 +149,10 @@ export default define(meta, async (ps, user) => {
}
});
const profile = await UserProfiles.findOne({ userId: user.id });
// この投稿をWatchする
if (user.autoWatch !== false) {
if (profile.autoWatch !== false) {
watch(user.id, note);
}