aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/components/AuthTokenSection.vue
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-09-25 18:19:42 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-01 17:16:09 +0200
commitb9bc2417e7a8dc81feb0abe20359bedaf864f790 (patch)
tree61b47fbf37c1d168da8625224debde9e6a985348 /apps/settings/src/components/AuthTokenSection.vue
parent7fb651235128dcbca8a6683b5cdafdf835f46300 (diff)
downloadnextcloud-server-b9bc2417e7a8dc81feb0abe20359bedaf864f790.tar.gz
nextcloud-server-b9bc2417e7a8dc81feb0abe20359bedaf864f790.zip
Comply to eslint
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/settings/src/components/AuthTokenSection.vue')
-rw-r--r--apps/settings/src/components/AuthTokenSection.vue272
1 files changed, 138 insertions, 134 deletions
diff --git a/apps/settings/src/components/AuthTokenSection.vue b/apps/settings/src/components/AuthTokenSection.vue
index c53256102d3..fe7ec640afb 100644
--- a/apps/settings/src/components/AuthTokenSection.vue
+++ b/apps/settings/src/components/AuthTokenSection.vue
@@ -22,155 +22,159 @@
<template>
<div id="security" class="section">
<h2>{{ t('settings', 'Devices & sessions') }}</h2>
- <p class="settings-hint hidden-when-empty">{{ t('settings', 'Web, desktop and mobile clients currently logged in to your account.') }}</p>
+ <p class="settings-hint hidden-when-empty">
+ {{ t('settings', 'Web, desktop and mobile clients currently logged in to your account.') }}
+ </p>
<AuthTokenList :tokens="tokens"
- @toggleScope="toggleTokenScope"
- @rename="rename"
- @delete="deleteToken"
- @wipe="wipeToken" />
+ @toggleScope="toggleTokenScope"
+ @rename="rename"
+ @delete="deleteToken"
+ @wipe="wipeToken" />
<AuthTokenSetupDialogue v-if="canCreateToken" :add="addNewToken" />
</div>
</template>
<script>
- import Axios from 'nextcloud-axios';
- import confirmPassword from 'nextcloud-password-confirmation';
-
- 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
- )
- })
- }
+import axios from 'nextcloud-axios'
+import confirmPassword from 'nextcloud-password-confirmation'
+
+import AuthTokenList from './AuthTokenList'
+import AuthTokenSetupDialogue from './AuthTokenSetupDialogue'
+
+const confirm = () => {
+ return new Promise(resolve => {
+ OC.dialogs.confirm(
+ t('core', 'Do you really want to wipe your data from this device?'),
+ t('core', 'Confirm wipe'),
+ resolve,
+ true
+ )
+ })
+}
+
+/**
+ * Tap into a promise without losing the value
+ * @param {Function} cb the callback
+ * @returns {any} val the value
+ */
+const tap = cb => val => {
+ cb(val)
+ return val
+}
+
+export default {
+ name: 'AuthTokenSection',
+ components: {
+ AuthTokenSetupDialogue,
+ AuthTokenList
+ },
+ props: {
+ tokens: {
+ type: Array,
+ required: true
+ },
+ canCreateToken: {
+ type: Boolean,
+ required: true
+ }
+ },
+ data() {
+ return {
+ baseUrl: OC.generateUrl('/settings/personal/authtokens')
+ }
+ },
+ methods: {
+ addNewToken(name) {
+ console.debug('creating a new app token', name)
- /**
- * Tap into a promise without losing the value
- */
- const tap = cb => val => {
- cb(val);
- return val;
- };
-
- export default {
- name: "AuthTokenSection",
- props: {
- tokens: {
- type: Array,
- required: true,
- },
- canCreateToken: {
- type: Boolean,
- required: true
+ const data = {
+ name
}
+ return axios.post(this.baseUrl, data)
+ .then(resp => resp.data)
+ .then(tap(() => console.debug('app token created')))
+ .then(tap(data => this.tokens.push(data.deviceToken)))
+ .catch(err => {
+ console.error.bind('could not create app password', err)
+ OC.Notification.showTemporary(t('core', 'Error while creating device token'))
+ throw err
+ })
},
- components: {
- AuthTokenSetupDialogue,
- AuthTokenList
+ toggleTokenScope(token, scope, value) {
+ console.debug('updating app token scope', token.id, scope, value)
+
+ const oldVal = token.scope[scope]
+ token.scope[scope] = value
+
+ return this.updateToken(token)
+ .then(tap(() => console.debug('app token scope updated')))
+ .catch(err => {
+ console.error.bind('could not update app token scope', err)
+ OC.Notification.showTemporary(t('core', 'Error while updating device token scope'))
+
+ // Restore
+ token.scope[scope] = oldVal
+
+ throw err
+ })
},
- data() {
- return {
- baseUrl: OC.generateUrl('/settings/personal/authtokens'),
- }
+ rename(token, newName) {
+ console.debug('renaming app token', token.id, token.name, newName)
+
+ const oldName = token.name
+ token.name = newName
+
+ return this.updateToken(token)
+ .then(tap(() => console.debug('app token name updated')))
+ .catch(err => {
+ console.error.bind('could not update app token name', err)
+ OC.Notification.showTemporary(t('core', 'Error while updating device token name'))
+
+ // Restore
+ token.name = oldName
+ })
+ },
+ updateToken(token) {
+ return axios.put(this.baseUrl + '/' + token.id, token)
+ .then(resp => resp.data)
+ },
+ deleteToken(token) {
+ console.debug('deleting app token', token)
+
+ this.tokens = this.tokens.filter(t => t !== token)
+
+ return axios.delete(this.baseUrl + '/' + token.id)
+ .then(resp => resp.data)
+ .then(tap(() => console.debug('app token deleted')))
+ .catch(err => {
+ console.error.bind('could not delete app token', err)
+ OC.Notification.showTemporary(t('core', 'Error while deleting the token'))
+
+ // Restore
+ this.tokens.push(token)
+ })
},
- methods: {
- addNewToken (name) {
- console.debug('creating a new app token', name);
-
- const data = {
- name,
- };
- return Axios.post(this.baseUrl, data)
- .then(resp => resp.data)
- .then(tap(() => console.debug('app token created')))
- .then(tap(data => this.tokens.push(data.deviceToken)))
- .catch(err => {
- console.error.bind('could not create app password', err);
- OC.Notification.showTemporary(t('core', 'Error while creating device token'));
- throw err;
- });
- },
- toggleTokenScope (token, scope, value) {
- console.debug('updating app token scope', token.id, scope, value);
-
- const oldVal = token.scope[scope];
- token.scope[scope] = value;
-
- return this.updateToken(token)
- .then(tap(() => console.debug('app token scope updated')))
- .catch(err => {
- console.error.bind('could not update app token scope', err);
- OC.Notification.showTemporary(t('core', 'Error while updating device token scope'));
-
- // Restore
- token.scope[scope] = oldVal;
-
- throw err;
- })
- },
- rename (token, newName) {
- console.debug('renaming app token', token.id, token.name, newName);
-
- const oldName = token.name;
- token.name = newName;
-
- return this.updateToken(token)
- .then(tap(() => console.debug('app token name updated')))
- .catch(err => {
- console.error.bind('could not update app token name', err);
- OC.Notification.showTemporary(t('core', 'Error while updating device token name'));
-
- // Restore
- token.name = oldName;
- })
- },
- updateToken (token) {
- return Axios.put(this.baseUrl + '/' + token.id, token)
- .then(resp => resp.data)
- },
- deleteToken (token) {
- console.debug('deleting app token', token);
-
- this.tokens = this.tokens.filter(t => t !== token);
-
- return Axios.delete(this.baseUrl + '/' + token.id)
- .then(resp => resp.data)
- .then(tap(() => console.debug('app token deleted')))
- .catch(err => {
- console.error.bind('could not delete app token', err);
- OC.Notification.showTemporary(t('core', 'Error while deleting the token'));
-
- // Restore
- this.tokens.push(token);
- })
- },
- async wipeToken(token) {
- console.debug('wiping app token', 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'));
+ async wipeToken(token) {
+ console.debug('wiping app token', 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'))
}
}
}
+}
</script>
<style scoped>