テーブル分割
This commit is contained in:
@ -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
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
});
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
});
|
||||
|
@ -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
|
||||
});
|
||||
});
|
||||
|
@ -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');
|
||||
|
@ -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');
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import * as speakeasy from 'speakeasy';
|
||||
import { publishMainStream } from '../../../services/stream';
|
||||
import signin from '../common/signin';
|
||||
import config from '../../../config';
|
||||
import { Users, Signins } from '../../../models';
|
||||
import { Users, Signins, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
|
||||
@ -45,13 +45,15 @@ export default async (ctx: Koa.BaseContext) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await UserProfiles.findOne({ userId: user.id });
|
||||
|
||||
// Compare password
|
||||
const same = await bcrypt.compare(password, user.password);
|
||||
const same = await bcrypt.compare(password, profile.password);
|
||||
|
||||
if (same) {
|
||||
if (user.twoFactorEnabled) {
|
||||
if (profile.twoFactorEnabled) {
|
||||
const verified = (speakeasy as any).totp.verify({
|
||||
secret: user.twoFactorSecret,
|
||||
secret: profile.twoFactorSecret,
|
||||
encoding: 'base32',
|
||||
token: token
|
||||
});
|
||||
|
@ -5,13 +5,13 @@ import generateUserToken from '../common/generate-native-user-token';
|
||||
import config from '../../../config';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import * as recaptcha from 'recaptcha-promise';
|
||||
import { Users, RegistrationTickets, UserServiceLinkings, UserKeypairs } from '../../../models';
|
||||
import { Users, RegistrationTickets, UserProfiles, UserKeypairs } from '../../../models';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
import { usersChart } from '../../../services/chart';
|
||||
import { UserServiceLinking } from '../../../models/entities/user-service-linking';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
||||
import { toPuny } from '../../../misc/convert-host';
|
||||
import { UserProfile } from '../../../models/entities/user-profile';
|
||||
|
||||
export default async (ctx: Koa.BaseContext) => {
|
||||
const body = ctx.request.body as any;
|
||||
@ -106,23 +106,21 @@ export default async (ctx: Koa.BaseContext) => {
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: toPuny(host),
|
||||
token: secret,
|
||||
password: hash,
|
||||
isAdmin: config.autoAdmin && usersCount === 0,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false
|
||||
} as User);
|
||||
|
||||
await UserKeypairs.save({
|
||||
id: genId(),
|
||||
publicKey: keyPair[0],
|
||||
privateKey: keyPair[1],
|
||||
userId: account.id
|
||||
} as UserKeypair);
|
||||
|
||||
await UserServiceLinkings.save({
|
||||
id: genId(),
|
||||
userId: account.id
|
||||
} as UserServiceLinking);
|
||||
await UserProfiles.save({
|
||||
userId: account.id,
|
||||
autoAcceptFollowed: true,
|
||||
autoWatch: false,
|
||||
password: hash,
|
||||
} as Partial<UserProfile>);
|
||||
|
||||
usersChart.update(account, true);
|
||||
|
||||
|
@ -8,7 +8,7 @@ import redis from '../../../db/redis';
|
||||
import * as uuid from 'uuid';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -45,7 +45,7 @@ router.get('/disconnect/discord', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
discord: false,
|
||||
@ -202,7 +202,7 @@ router.get('/dc/cb', async ctx => {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const profile = await UserProfiles.createQueryBuilder()
|
||||
.where('discord @> :discord', {
|
||||
discord: {
|
||||
id: id,
|
||||
@ -211,12 +211,12 @@ router.get('/dc/cb', async ctx => {
|
||||
.andWhere('userHost IS NULL')
|
||||
.getOne();
|
||||
|
||||
if (link == null) {
|
||||
if (profile == null) {
|
||||
ctx.throw(404, `@${username}#${discriminator}と連携しているMisskeyアカウントはありませんでした...`);
|
||||
return;
|
||||
}
|
||||
|
||||
await UserServiceLinkings.update(link.id, {
|
||||
await UserProfiles.update({ userId: profile.userId }, {
|
||||
discord: true,
|
||||
discordAccessToken: accessToken,
|
||||
discordRefreshToken: refreshToken,
|
||||
@ -225,7 +225,7 @@ router.get('/dc/cb', async ctx => {
|
||||
discordDiscriminator: discriminator
|
||||
});
|
||||
|
||||
signin(ctx, await Users.findOne(link.userId) as ILocalUser, true);
|
||||
signin(ctx, await Users.findOne(profile.userId) as ILocalUser, true);
|
||||
} else {
|
||||
const code = ctx.query.code;
|
||||
|
||||
@ -289,7 +289,7 @@ router.get('/dc/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
discord: true,
|
||||
discordAccessToken: accessToken,
|
||||
discordRefreshToken: refreshToken,
|
||||
|
@ -8,7 +8,7 @@ import redis from '../../../db/redis';
|
||||
import * as uuid from 'uuid';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -45,7 +45,7 @@ router.get('/disconnect/github', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
github: false,
|
||||
@ -191,7 +191,7 @@ router.get('/gh/cb', async ctx => {
|
||||
return;
|
||||
}
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const link = await UserProfiles.createQueryBuilder()
|
||||
.where('github @> :github', {
|
||||
github: {
|
||||
id: id,
|
||||
@ -263,7 +263,7 @@ router.get('/gh/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
github: true,
|
||||
githubAccessToken: accessToken,
|
||||
githubId: id,
|
||||
|
@ -7,7 +7,7 @@ import { publishMainStream } from '../../../services/stream';
|
||||
import config from '../../../config';
|
||||
import signin from '../common/signin';
|
||||
import fetchMeta from '../../../misc/fetch-meta';
|
||||
import { Users, UserServiceLinkings } from '../../../models';
|
||||
import { Users, UserProfiles } from '../../../models';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
|
||||
function getUserToken(ctx: Koa.BaseContext) {
|
||||
@ -44,7 +44,7 @@ router.get('/disconnect/twitter', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({
|
||||
await UserProfiles.update({
|
||||
userId: user.id
|
||||
}, {
|
||||
twitter: false,
|
||||
@ -139,7 +139,7 @@ router.get('/tw/cb', async ctx => {
|
||||
|
||||
const result = await twAuth.done(JSON.parse(twCtx), ctx.query.oauth_verifier);
|
||||
|
||||
const link = await UserServiceLinkings.createQueryBuilder()
|
||||
const link = await UserProfiles.createQueryBuilder()
|
||||
.where('twitter @> :twitter', {
|
||||
twitter: {
|
||||
userId: result.userId,
|
||||
@ -177,7 +177,7 @@ router.get('/tw/cb', async ctx => {
|
||||
token: userToken
|
||||
});
|
||||
|
||||
await UserServiceLinkings.update({ userId: user.id }, {
|
||||
await UserProfiles.update({ userId: user.id }, {
|
||||
twitter: true,
|
||||
twitterAccessToken: result.accessToken,
|
||||
twitterAccessTokenSecret: result.accessTokenSecret,
|
||||
|
Reference in New Issue
Block a user