From c77feca64bbf648a076b4931197f9ac241a7d9ba Mon Sep 17 00:00:00 2001
From: Christoph Wurst <christoph@winzerhof-wurst.at>
Date: Tue, 28 May 2019 16:44:41 +0200
Subject: Let the user confirm the remote wipe

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
---
 settings/src/components/AuthTokenSection.vue | 41 ++++++++++++++++++----------
 1 file changed, 27 insertions(+), 14 deletions(-)

(limited to 'settings/src/components/AuthTokenSection.vue')

diff --git a/settings/src/components/AuthTokenSection.vue b/settings/src/components/AuthTokenSection.vue
index 0f2da49e053..c74348631db 100644
--- a/settings/src/components/AuthTokenSection.vue
+++ b/settings/src/components/AuthTokenSection.vue
@@ -39,6 +39,17 @@
 	import AuthTokenList from './AuthTokenList';
 	import AuthTokenSetupDialogue from './AuthTokenSetupDialogue';
 
+	const confirm = () => {
+		return new Promise(res => {
+			OC.dialogs.confirm(
+				t('core', 'Do you really want to wipe your data from this device?'),
+				t('core', 'Confirm wipe'),
+				res,
+				true
+			)
+		})
+	}
+
 	/**
 	 * Tap into a promise without losing the value
 	 */
@@ -135,22 +146,24 @@
 						this.tokens.push(token);
 					})
 			},
-			wipeToken(token) {
+			async wipeToken(token) {
 				console.debug('wiping app token', token);
 
-				confirmPassword()
-					.then(() => Axios.post(this.baseUrl + '/wipe/' + token.id))
-					.then(tap(() => {
-						console.debug('app token marked for wipe')
-
-						// Update the type
-						// TODO: refactor the server-side code to return the updated token
-						token.type = 2;
-					}))
-					.catch(err => {
-						console.error.bind('could not wipe app token', err);
-						OC.Notification.showTemporary(t('core', 'Error while wiping the device with the token'));
-					})
+				try {
+					await confirmPassword()
+
+					if (!(await confirm())) {
+						console.debug('wipe aborted by user')
+						return;
+					}
+					await Axios.post(this.baseUrl + '/wipe/' + token.id)
+					console.debug('app token marked for wipe')
+
+					token.type = 2;
+				} catch (err) {
+					console.error('could not wipe app token', err);
+					OC.Notification.showTemporary(t('core', 'Error while wiping the device with the token'));
+				}
 			}
 		}
 	}
-- 
cgit v1.2.3

