diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:20:40 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:54:41 +0900 |
| commit | 90f8fe7e538bb7e52d2558152a0390e693f39b11 (patch) | |
| tree | 0f830887053c8f352b1cd0c13ca715fd14c1f030 /src/api/endpoints/i/2fa | |
| parent | Implement remote account resolution (diff) | |
| download | sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.gz sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.bz2 sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.zip | |
Introduce processor
Diffstat (limited to 'src/api/endpoints/i/2fa')
| -rw-r--r-- | src/api/endpoints/i/2fa/done.ts | 37 | ||||
| -rw-r--r-- | src/api/endpoints/i/2fa/register.ts | 48 | ||||
| -rw-r--r-- | src/api/endpoints/i/2fa/unregister.ts | 28 |
3 files changed, 0 insertions, 113 deletions
diff --git a/src/api/endpoints/i/2fa/done.ts b/src/api/endpoints/i/2fa/done.ts deleted file mode 100644 index 0f1db73829..0000000000 --- a/src/api/endpoints/i/2fa/done.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import * as speakeasy from 'speakeasy'; -import User from '../../../models/user'; - -module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'token' parameter - const [token, tokenErr] = $(params.token).string().$; - if (tokenErr) return rej('invalid token param'); - - const _token = token.replace(/\s/g, ''); - - if (user.two_factor_temp_secret == null) { - return rej('二段階認証の設定が開始されていません'); - } - - const verified = (speakeasy as any).totp.verify({ - secret: user.two_factor_temp_secret, - encoding: 'base32', - token: _token - }); - - if (!verified) { - return rej('not verified'); - } - - await User.update(user._id, { - $set: { - 'account.two_factor_secret': user.two_factor_temp_secret, - 'account.two_factor_enabled': true - } - }); - - res(); -}); diff --git a/src/api/endpoints/i/2fa/register.ts b/src/api/endpoints/i/2fa/register.ts deleted file mode 100644 index 24abfcdfc5..0000000000 --- a/src/api/endpoints/i/2fa/register.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import * as bcrypt from 'bcryptjs'; -import * as speakeasy from 'speakeasy'; -import * as QRCode from 'qrcode'; -import User from '../../../models/user'; -import config from '../../../../conf'; - -module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'password' parameter - const [password, passwordErr] = $(params.password).string().$; - if (passwordErr) return rej('invalid password param'); - - // Compare password - const same = await bcrypt.compare(password, user.account.password); - - if (!same) { - return rej('incorrect password'); - } - - // Generate user's secret key - const secret = speakeasy.generateSecret({ - length: 32 - }); - - await User.update(user._id, { - $set: { - two_factor_temp_secret: secret.base32 - } - }); - - // Get the data URL of the authenticator URL - QRCode.toDataURL(speakeasy.otpauthURL({ - secret: secret.base32, - encoding: 'base32', - label: user.username, - issuer: config.host - }), (err, data_url) => { - res({ - qr: data_url, - secret: secret.base32, - label: user.username, - issuer: config.host - }); - }); -}); diff --git a/src/api/endpoints/i/2fa/unregister.ts b/src/api/endpoints/i/2fa/unregister.ts deleted file mode 100644 index c43f9ccc44..0000000000 --- a/src/api/endpoints/i/2fa/unregister.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import * as bcrypt from 'bcryptjs'; -import User from '../../../models/user'; - -module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'password' parameter - const [password, passwordErr] = $(params.password).string().$; - if (passwordErr) return rej('invalid password param'); - - // Compare password - const same = await bcrypt.compare(password, user.account.password); - - if (!same) { - return rej('incorrect password'); - } - - await User.update(user._id, { - $set: { - 'account.two_factor_secret': null, - 'account.two_factor_enabled': false - } - }); - - res(); -}); |