aboutsummaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/src
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/twofactor_backupcodes/src
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/twofactor_backupcodes/src')
-rw-r--r--apps/twofactor_backupcodes/src/service/BackupCodesService.js4
-rw-r--r--apps/twofactor_backupcodes/src/service/PrintService.js14
-rw-r--r--apps/twofactor_backupcodes/src/settings.js10
-rw-r--r--apps/twofactor_backupcodes/src/store.js44
-rw-r--r--apps/twofactor_backupcodes/src/views/PersonalSettings.vue159
5 files changed, 122 insertions, 109 deletions
diff --git a/apps/twofactor_backupcodes/src/service/BackupCodesService.js b/apps/twofactor_backupcodes/src/service/BackupCodesService.js
index a42b7b8b5ad..0657fd8ca1a 100644
--- a/apps/twofactor_backupcodes/src/service/BackupCodesService.js
+++ b/apps/twofactor_backupcodes/src/service/BackupCodesService.js
@@ -1,7 +1,7 @@
import Axios from 'nextcloud-axios'
-export function generateCodes () {
- const url = OC.generateUrl('/apps/twofactor_backupcodes/settings/create');
+export function generateCodes() {
+ const url = OC.generateUrl('/apps/twofactor_backupcodes/settings/create')
return Axios.post(url, {}).then(resp => resp.data)
}
diff --git a/apps/twofactor_backupcodes/src/service/PrintService.js b/apps/twofactor_backupcodes/src/service/PrintService.js
index 7f4a0f46c59..7383edfdf46 100644
--- a/apps/twofactor_backupcodes/src/service/PrintService.js
+++ b/apps/twofactor_backupcodes/src/service/PrintService.js
@@ -1,8 +1,8 @@
-export function print (data) {
- const name = OC.theme.name || 'Nextcloud';
- const newTab = window.open('', t('twofactor_backupcodes', '{name} backup codes', {name: name}));
- newTab.document.write('<h1>' + t('twofactor_backupcodes', '{name} backup codes', {name: name}) + '</h1>');
- newTab.document.write('<pre>' + data + '</pre>');
- newTab.print();
- newTab.close();
+export function print(data) {
+ const name = OC.theme.name || 'Nextcloud'
+ const newTab = window.open('', t('twofactor_backupcodes', '{name} backup codes', { name: name }))
+ newTab.document.write('<h1>' + t('twofactor_backupcodes', '{name} backup codes', { name: name }) + '</h1>')
+ newTab.document.write('<pre>' + data + '</pre>')
+ newTab.print()
+ newTab.close()
}
diff --git a/apps/twofactor_backupcodes/src/settings.js b/apps/twofactor_backupcodes/src/settings.js
index 5a8251121da..89a56ee2e5a 100644
--- a/apps/twofactor_backupcodes/src/settings.js
+++ b/apps/twofactor_backupcodes/src/settings.js
@@ -1,10 +1,10 @@
-import Vue from 'vue';
-import PersonalSettings from './views/PersonalSettings';
-import store from './store';
+import Vue from 'vue'
+import PersonalSettings from './views/PersonalSettings'
+import store from './store'
-Vue.prototype.t = t;
+Vue.prototype.t = t
-const initialState = OCP.InitialState.loadState('twofactor_backupcodes', 'state');
+const initialState = OCP.InitialState.loadState('twofactor_backupcodes', 'state')
store.replaceState(
initialState
)
diff --git a/apps/twofactor_backupcodes/src/store.js b/apps/twofactor_backupcodes/src/store.js
index 3af299ca619..18f2d26bc18 100644
--- a/apps/twofactor_backupcodes/src/store.js
+++ b/apps/twofactor_backupcodes/src/store.js
@@ -1,4 +1,4 @@
-/*
+/**
* @copyright 2019 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author 2019 Roeland Jago Douma <roeland@famdouma.nl>
@@ -11,7 +11,7 @@
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
@@ -21,12 +21,18 @@
import Vue from 'vue'
import Vuex from 'vuex'
-
-import {generateCodes} from './service/BackupCodesService'
+import { generateCodes } from './service/BackupCodesService'
Vue.use(Vuex)
-export const mutations = {
+const state = {
+ enabled: false,
+ total: 0,
+ used: 0,
+ codes: []
+}
+
+const mutations = {
setEnabled(state, enabled) {
Vue.set(state, 'enabled', enabled)
},
@@ -41,29 +47,23 @@ export const mutations = {
}
}
-export const actions = {
- generate ({commit}) {
- commit('setEnabled', false);
+const actions = {
+ generate({ commit }) {
+ commit('setEnabled', false)
- return generateCodes()
- .then(({codes, state}) => {
- commit('setEnabled', state.enabled);
- commit('setTotal', state.total);
- commit('setUsed', state.used);
- commit('setCodes', codes);
- return true;
- });
+ return generateCodes().then(({ codes, state }) => {
+ commit('setEnabled', state.enabled)
+ commit('setTotal', state.total)
+ commit('setUsed', state.used)
+ commit('setCodes', codes)
+ return true
+ })
}
}
export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
- state: {
- enabled: false,
- total: 0,
- used: 0,
- codes: undefined
- },
+ state,
mutations,
actions
})
diff --git a/apps/twofactor_backupcodes/src/views/PersonalSettings.vue b/apps/twofactor_backupcodes/src/views/PersonalSettings.vue
index 15e20395e1b..d05e8b360af 100644
--- a/apps/twofactor_backupcodes/src/views/PersonalSettings.vue
+++ b/apps/twofactor_backupcodes/src/views/PersonalSettings.vue
@@ -1,107 +1,120 @@
<template>
<div>
<button v-if="!enabled"
- id="generate-backup-codes"
- v-on:click="generateBackupCodes">{{ t('twofactor_backupcodes', 'Generate backup codes') }}</button>
+ id="generate-backup-codes"
+ @click="generateBackupCodes">
+ {{ t('twofactor_backupcodes', 'Generate backup codes') }}
+ </button>
<template v-else>
<p>
- <template v-if="!codes">
+ <template v-if="!haveCodes">
{{ t('twofactor_backupcodes', 'Backup codes have been generated. {used} of {total} codes have been used.', {used, total}) }}
</template>
<template v-else>
{{ t('twofactor_backupcodes', 'These are your backup codes. Please save and/or print them as you will not be able to read the codes again later') }}
<ul>
- <li v-for="code in codes" class="backup-code">{{code}}</li>
+ <li v-for="code in codes" :key="code" class="backup-code">
+ {{ code }}
+ </li>
</ul>
<a :href="downloadUrl"
- class="button primary"
- :download="downloadFilename">{{ t('twofactor_backupcodes', 'Save backup codes') }}</a>
+ class="button primary"
+ :download="downloadFilename">{{ t('twofactor_backupcodes', 'Save backup codes') }}</a>
<button class="button"
- v-on:click="printCodes">{{ t('twofactor_backupcodes', 'Print backup codes') }}</button>
+ @click="printCodes">
+ {{ t('twofactor_backupcodes', 'Print backup codes') }}
+ </button>
</template>
</p>
<p>
<button id="generate-backup-codes"
- :class="{'icon-loading-small': generatingCodes}"
- v-on:click="generateBackupCodes">{{ t('twofactor_backupcodes', 'Regenerate backup codes') }}</button>
+ :class="{'icon-loading-small': generatingCodes}"
+ @click="generateBackupCodes">
+ {{ t('twofactor_backupcodes', 'Regenerate backup codes') }}
+ </button>
+ </p>
+ <p>
+ <em>
+ {{ t('twofactor_backupcodes', 'If you regenerate backup codes, you automatically invalidate old codes.') }}
+ </em>
</p>
- <p><em>
- {{ t('twofactor_backupcodes', 'If you regenerate backup codes, you automatically invalidate old codes.') }}
- </em></p>
</template>
</div>
</template>
<script>
- import confirmPassword from 'nextcloud-password-confirmation';
- import {print} from '../service/PrintService';
+import confirmPassword from 'nextcloud-password-confirmation'
+import { print } from '../service/PrintService'
- export default {
- name: "PersonalSettings",
- data() {
- return {
- generatingCodes: false,
- };
- },
- computed: {
- downloadUrl: function() {
- if (!this.codes) {
- return '';
- }
- return 'data:text/plain,' + encodeURIComponent(this.codes.reduce((prev, code) => {
- return prev + code + '\r\n';
- }, ''));
- },
- downloadFilename: function() {
- const name = OC.theme.name || 'Nextcloud';
- return name + '-backup-codes.txt';
- },
- enabled: function() {
- return this.$store.state.enabled
- },
- total: function() {
- return this.$store.state.total
- },
- used: function() {
- return this.$store.state.used
- },
- codes: function() {
- return this.$store.state.codes
- },
- name: function() {
- return OC.theme.name || 'Nextcloud'
+export default {
+ name: 'PersonalSettings',
+ data() {
+ return {
+ generatingCodes: false
+ }
+ },
+ computed: {
+ downloadUrl: function() {
+ if (!this.codes) {
+ return ''
}
+ return 'data:text/plain,' + encodeURIComponent(this.codes.reduce((prev, code) => {
+ return prev + code + '\r\n'
+ }, ''))
},
- methods: {
- generateBackupCodes: function() {
- confirmPassword().then(() => {
- // Hide old codes
- this.generatingCodes = true;
-
- this.$store.dispatch('generate').then(data => {
- this.generatingCodes = false;
- }).catch(err => {
- OC.Notification.showTemporary(t('twofactor_backupcodes', 'An error occurred while generating your backup codes'));
- this.generatingCodes = false;
- throw err;
- });
- }).catch(console.error.bind(this));
- },
+ downloadFilename: function() {
+ const name = OC.theme.name || 'Nextcloud'
+ return name + '-backup-codes.txt'
+ },
+ enabled: function() {
+ return this.$store.state.enabled
+ },
+ total: function() {
+ return this.$store.state.total
+ },
+ used: function() {
+ return this.$store.state.used
+ },
+ codes: function() {
+ return this.$store.state.codes
+ },
+ name: function() {
+ return OC.theme.name || 'Nextcloud'
+ },
+ haveCodes() {
+ return this.codes && this.codes.length > 0
+ }
+ },
+ methods: {
+ generateBackupCodes: function() {
+ confirmPassword().then(() => {
+ // Hide old codes
+ this.generatingCodes = true
- getPrintData: function(codes) {
- if (!codes) {
- return '';
- }
- return codes.reduce((prev, code) => {
- return prev + code + "<br>";
- }, '');
- },
+ this.$store.dispatch('generate').then(data => {
+ this.generatingCodes = false
+ }).catch(err => {
+ OC.Notification.showTemporary(t('twofactor_backupcodes', 'An error occurred while generating your backup codes'))
+ this.generatingCodes = false
+ throw err
+ })
+ }).catch(console.error.bind(this))
+ },
- printCodes: function() {
- print(this.getPrintData(this.codes));
+ getPrintData: function(codes) {
+ if (!codes) {
+ return ''
}
+ return codes.reduce((prev, code) => {
+ return prev + code + '<br>'
+ }, '')
+ },
+
+ printCodes: function() {
+ print(this.getPrintData(this.codes))
}
}
+}
</script>
<style scoped>