summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-12-10 02:45:32 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-12-10 02:45:32 +0900
commitd0cfe112e11c52acaeebb42c3229a37af23c846a (patch)
treeff032473cc4a83c6b8d9c9baf6d38e82eef94eec /src/api
parent:+1: (diff)
downloadsharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.tar.gz
sharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.tar.bz2
sharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.zip
#973
Diffstat (limited to 'src/api')
-rw-r--r--src/api/endpoints.ts17
-rw-r--r--src/api/endpoints/i/2fa/unregister.ts28
2 files changed, 41 insertions, 4 deletions
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index 49871c0ce3..1138df193b 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -157,11 +157,18 @@ const endpoints: Endpoint[] = [
},
{
name: 'i/2fa/register',
- withCredential: true
+ withCredential: true,
+ secure: true
+ },
+ {
+ name: 'i/2fa/unregister',
+ withCredential: true,
+ secure: true
},
{
name: 'i/2fa/done',
- withCredential: true
+ withCredential: true,
+ secure: true
},
{
name: 'i/update',
@@ -179,11 +186,13 @@ const endpoints: Endpoint[] = [
},
{
name: 'i/change_password',
- withCredential: true
+ withCredential: true,
+ secure: true
},
{
name: 'i/regenerate_token',
- withCredential: true
+ withCredential: true,
+ secure: true
},
{
name: 'i/pin',
diff --git a/src/api/endpoints/i/2fa/unregister.ts b/src/api/endpoints/i/2fa/unregister.ts
new file mode 100644
index 0000000000..6bee6a26f2
--- /dev/null
+++ b/src/api/endpoints/i/2fa/unregister.ts
@@ -0,0 +1,28 @@
+/**
+ * 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.password);
+
+ if (!same) {
+ return rej('incorrect password');
+ }
+
+ await User.update(user._id, {
+ $set: {
+ two_factor_secret: null,
+ two_factor_enabled: false
+ }
+ });
+
+ res();
+});