diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-10 15:04:27 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-10 15:04:27 +0900 |
| commit | 626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c (patch) | |
| tree | 23b89c000b1b169c36cffc7a345a2fc1ebe33347 /src/server/api/endpoints | |
| parent | Delete get-user-summary.ts (diff) | |
| download | sharkey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.tar.gz sharkey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.tar.bz2 sharkey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.zip | |
テーブル分割
Diffstat (limited to 'src/server/api/endpoints')
| -rw-r--r-- | src/server/api/endpoints/admin/reset-password.ts | 6 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/2fa/done.ts | 16 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/2fa/register.ts | 8 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/2fa/unregister.ts | 10 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/change-password.ts | 8 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/delete-account.ts | 6 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/regenerate-token.ts | 6 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/update-client-setting.ts | 4 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/update-email.ts | 10 | ||||
| -rw-r--r-- | src/server/api/endpoints/i/update.ts | 28 | ||||
| -rw-r--r-- | src/server/api/endpoints/notes/polls/vote.ts | 6 |
11 files changed, 64 insertions, 44 deletions
diff --git a/src/server/api/endpoints/admin/reset-password.ts b/src/server/api/endpoints/admin/reset-password.ts index 07b8b6d938..42df668606 100644 --- a/src/server/api/endpoints/admin/reset-password.ts +++ b/src/server/api/endpoints/admin/reset-password.ts @@ -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 }); diff --git a/src/server/api/endpoints/i/2fa/done.ts b/src/server/api/endpoints/i/2fa/done.ts index 8ccb09b8b7..edc7cefd26 100644 --- a/src/server/api/endpoints/i/2fa/done.ts +++ b/src/server/api/endpoints/i/2fa/done.ts @@ -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 }); }); diff --git a/src/server/api/endpoints/i/2fa/register.ts b/src/server/api/endpoints/i/2fa/register.ts index 5efe77900a..db9a2fe944 100644 --- a/src/server/api/endpoints/i/2fa/register.ts +++ b/src/server/api/endpoints/i/2fa/register.ts @@ -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 }); diff --git a/src/server/api/endpoints/i/2fa/unregister.ts b/src/server/api/endpoints/i/2fa/unregister.ts index fb3ecd4043..fa25b74391 100644 --- a/src/server/api/endpoints/i/2fa/unregister.ts +++ b/src/server/api/endpoints/i/2fa/unregister.ts @@ -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; }); diff --git a/src/server/api/endpoints/i/change-password.ts b/src/server/api/endpoints/i/change-password.ts index f8f977200f..d0e0695e18 100644 --- a/src/server/api/endpoints/i/change-password.ts +++ b/src/server/api/endpoints/i/change-password.ts @@ -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 }); }); diff --git a/src/server/api/endpoints/i/delete-account.ts b/src/server/api/endpoints/i/delete-account.ts index 5aff74e0cc..7ef7aa5fac 100644 --- a/src/server/api/endpoints/i/delete-account.ts +++ b/src/server/api/endpoints/i/delete-account.ts @@ -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'); diff --git a/src/server/api/endpoints/i/regenerate-token.ts b/src/server/api/endpoints/i/regenerate-token.ts index 729c1a300a..ec53bca979 100644 --- a/src/server/api/endpoints/i/regenerate-token.ts +++ b/src/server/api/endpoints/i/regenerate-token.ts @@ -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'); diff --git a/src/server/api/endpoints/i/update-client-setting.ts b/src/server/api/endpoints/i/update-client-setting.ts index edbfe28f35..49bcb35ae6 100644 --- a/src/server/api/endpoints/i/update-client-setting.ts +++ b/src/server/api/endpoints/i/update-client-setting.ts @@ -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 diff --git a/src/server/api/endpoints/i/update-email.ts b/src/server/api/endpoints/i/update-email.ts index 253017535f..d98f0d753e 100644 --- a/src/server/api/endpoints/i/update-email.ts +++ b/src/server/api/endpoints/i/update-email.ts @@ -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 }); diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 54e7f33bdb..ffc90b2f51 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -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, diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts index 7d0ed6e4f9..d868234dc9 100644 --- a/src/server/api/endpoints/notes/polls/vote.ts +++ b/src/server/api/endpoints/notes/polls/vote.ts @@ -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); } |