summaryrefslogtreecommitdiff
path: root/src
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
parent:+1: (diff)
downloadsharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.tar.gz
sharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.tar.bz2
sharkey-d0cfe112e11c52acaeebb42c3229a37af23c846a.zip
#973
Diffstat (limited to 'src')
-rw-r--r--src/api/endpoints.ts17
-rw-r--r--src/api/endpoints/i/2fa/unregister.ts28
-rw-r--r--src/web/app/desktop/tags/settings.tag21
3 files changed, 61 insertions, 5 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();
+});
diff --git a/src/web/app/desktop/tags/settings.tag b/src/web/app/desktop/tags/settings.tag
index 9f71da6876..3fa1f50fce 100644
--- a/src/web/app/desktop/tags/settings.tag
+++ b/src/web/app/desktop/tags/settings.tag
@@ -266,7 +266,11 @@
<mk-2fa-setting>
<p>%i18n:desktop.tags.mk-2fa-setting.intro%<a href="%i18n:desktop.tags.mk-2fa-setting.url%" target="_blank">%i18n:desktop.tags.mk-2fa-setting.detail%</a></p>
<div class="ui info warn"><p>%fa:exclamation-triangle%%i18n:desktop.tags.mk-2fa-setting.caution%</p></div>
- <p if={ !data }><button onclick={ register } class="ui primary">%i18n:desktop.tags.mk-2fa-setting.register%</button></p>
+ <p if={ !data && !I.two_factor_enabled }><button onclick={ register } class="ui primary">%i18n:desktop.tags.mk-2fa-setting.register%</button></p>
+ <virtual if={ I.two_factor_enabled }>
+ <p>%i18n:desktop.tags.mk-2fa-setting.already-registered%</p>
+ <button onclick={ unregister } class="ui">%i18n:desktop.tags.mk-2fa-setting.unregister%</button>
+ </virtual>
<div if={ data }>
<ol>
<li>%i18n:desktop.tags.mk-2fa-setting.authenticator% <a href="https://support.google.com/accounts/answer/1066447" target="_blank">%i18n:desktop.tags.mk-2fa-setting.howtoinstall%</a></li>
@@ -288,6 +292,7 @@
import passwordDialog from '../scripts/password-dialog';
import notify from '../scripts/notify';
+ this.mixin('i');
this.mixin('api');
this.register = () => {
@@ -302,11 +307,25 @@
});
};
+ this.unregister = () => {
+ passwordDialog('%i18n:desktop.tags.mk-2fa-setting.enter-password%', password => {
+ this.api('i/2fa/unregister', {
+ password: password
+ }).then(data => {
+ notify('%i18n:desktop.tags.mk-2fa-setting.unregistered%');
+ this.I.two_factor_enabled = false;
+ this.I.update();
+ });
+ });
+ };
+
this.submit = () => {
this.api('i/2fa/done', {
token: this.refs.token.value
}).then(() => {
notify('%i18n:desktop.tags.mk-2fa-setting.success%');
+ this.I.two_factor_enabled = true;
+ this.I.update();
}).catch(() => {
notify('%i18n:desktop.tags.mk-2fa-setting.failed%');
});