summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/i/2fa
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-10 15:04:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-10 15:04:27 +0900
commit626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c (patch)
tree23b89c000b1b169c36cffc7a345a2fc1ebe33347 /src/server/api/endpoints/i/2fa
parentDelete get-user-summary.ts (diff)
downloadmisskey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.tar.gz
misskey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.tar.bz2
misskey-626cfb61ac3940bee7a3acf1b1c5c4cae4ae410c.zip
テーブル分割
Diffstat (limited to 'src/server/api/endpoints/i/2fa')
-rw-r--r--src/server/api/endpoints/i/2fa/done.ts16
-rw-r--r--src/server/api/endpoints/i/2fa/register.ts8
-rw-r--r--src/server/api/endpoints/i/2fa/unregister.ts10
3 files changed, 19 insertions, 15 deletions
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;
});