Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 78 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"@nextcloud/router": "^3.0.1",
"@nextcloud/vue": "^8.23.1",
"@simplewebauthn/browser": "^13.1.0",
"pinia": "^2.3.1",
"vue": "^2.7.16",
"vue-click-outside": "^1.1.0",
"vue-material-design-icons": "^5.3.1",
"vuex": "^3.6.2"
"vue-material-design-icons": "^5.3.1"
},
"devDependencies": {
"@nextcloud/babel-config": "^1.2.0",
Expand Down
8 changes: 7 additions & 1 deletion src/components/AddDeviceDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div v-else-if="step === RegistrationSteps.NAMING"
class="new-webauthn-device">
<span class="icon-loading-small webauthn-loading" />
<form @submit.prevent="submit" class="new-webauthn-device__form">

Check warning on line 27 in src/components/AddDeviceDialog.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Attribute "class" should go before "@submit.prevent"
<input v-model="name"
required
type="text"
Expand Down Expand Up @@ -54,6 +54,8 @@
import { startRegistration } from '@simplewebauthn/browser'
import * as RegistrationService from '../services/RegistrationService.js'
import logger from '../logger.js'
import { mapStores } from 'pinia'
import { useMainStore } from '../store.js'

const RegistrationSteps = Object.freeze({
READY: 1,
Expand Down Expand Up @@ -83,6 +85,10 @@
}
},

computed: {
...mapStores(useMainStore),
},

methods: {
async start() {
this.errorMessage = null
Expand Down Expand Up @@ -134,7 +140,7 @@
this.name,
JSON.stringify(this.registrationResponse),
)
this.$store.commit('addDevice', device)
this.mainStore.addDevice(device)
logger.debug('new device added to store', { device })
} catch (error) {
logger.error('Error persisting webauthn registration', { error })
Expand Down
7 changes: 3 additions & 4 deletions src/components/Challenge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
</template>

<script>
import { mapGetters } from 'vuex'
import { NcButton } from '@nextcloud/vue'
import { browserSupportsWebAuthn, startAuthentication } from '@simplewebauthn/browser'
import logger from '../logger.js'
import { mapState } from 'pinia'
import { useMainStore } from '../store.js'

export default {
name: 'Challenge',
Expand All @@ -66,9 +67,7 @@ export default {
},

computed: {
...mapGetters({
credentialRequestOptions: 'getCredentialRequestOptions',
}),
...mapState(useMainStore, ['credentialRequestOptions']),
httpWarning() {
return document.location.protocol !== 'https:'
},
Expand Down
7 changes: 5 additions & 2 deletions src/components/Device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import InformationOutline from 'vue-material-design-icons/InformationOutline.vue'
import { confirmPassword } from '@nextcloud/password-confirmation'
import moment from '@nextcloud/moment'
import { mapStores } from 'pinia'
import { useMainStore } from '../store.js'

export default {
name: 'Device',
Expand All @@ -45,9 +47,9 @@
InformationOutline,
},
props: {
entityId: Number,

Check warning on line 50 in src/components/Device.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Prop 'entityId' requires default value to be set
id: String,

Check warning on line 51 in src/components/Device.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Prop 'id' requires default value to be set
name: String,

Check warning on line 52 in src/components/Device.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Prop 'name' requires default value to be set
active: Boolean,
createdAt: {
type: Number,
Expand All @@ -55,6 +57,7 @@
},
},
computed: {
...mapStores(useMainStore),
createdAtFormatted() {
if (!this.createdAt) {
return
Expand All @@ -67,15 +70,15 @@
async onDelete() {
try {
await confirmPassword()
await this.$store.dispatch('removeDevice', this.entityId)
await this.mainStore.removeDevice(this.entityId)
} catch (e) {
console.error('could not delete device', e)
}
},
async changeActivation(active) {
try {
await confirmPassword()
await this.$store.dispatch('changeActivationState', {
await this.mainStore.changeActivationState({
entityId: this.entityId,
active,
})
Expand Down
9 changes: 4 additions & 5 deletions src/components/PersonalSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
</template>

<script>

import AddDeviceDialog from './AddDeviceDialog.vue'
import Device from './Device.vue'
import { mapState } from 'pinia'
import { useMainStore } from '../store.js'

export default {
name: 'PersonalSettings',
Expand All @@ -55,11 +56,9 @@ export default {
}
},
computed: {
devices() {
return this.$store.state.devices
},
...mapState(useMainStore, ['devices']),
allDeactivated() {
return this.$store.state.devices.length > 0 && this.$store.state.devices.every(device => !device.active)
return this.devices.length > 0 && this.devices.every(device => !device.active)
},
},
}
Expand Down
13 changes: 10 additions & 3 deletions src/main-challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import store from './store.js'
import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'
import Nextcloud from './mixins/Nextcloud.js'
import Challenge from './components/Challenge.vue'
import { loadState } from '@nextcloud/initial-state'
import { useMainStore } from './store.js'

Vue.mixin(Nextcloud)

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

const credentialRequestOptions = loadState('twofactor_webauthn', 'credential-request-options')
store.commit('setCredentialRequestOptions', credentialRequestOptions)
const mainStore = useMainStore(pinia)
mainStore.$patch({
credentialRequestOptions,
})

export default new Vue({
el: '#twofactor-webauthn-challenge',
store,
pinia,
render: h => h(Challenge),
})
7 changes: 5 additions & 2 deletions src/main-login-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
*/

import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'

import Nextcloud from './mixins/Nextcloud.js'
import store from './store.js'

import LoginSetup from './components/LoginSetup.vue'

Vue.mixin(Nextcloud)

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

const View = Vue.extend(LoginSetup)
new View({ store }).$mount('#twofactor-webauthn-login-setup')
new View({ pinia }).$mount('#twofactor-webauthn-login-setup')
11 changes: 8 additions & 3 deletions src/main-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
*/

import { loadState } from '@nextcloud/initial-state'
import store from './store.js'
import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'

import Nextcloud from './mixins/Nextcloud.js'
import PersonalSettings from './components/PersonalSettings.vue'
import { useMainStore } from './store.js'

import '@nextcloud/password-confirmation/dist/style.css'

Vue.mixin(Nextcloud)

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

const devices = loadState('twofactor_webauthn', 'devices')
devices.sort((d1, d2) => {
if (!d1.name) {
Expand All @@ -24,7 +28,8 @@ devices.sort((d1, d2) => {
return d1.name.localeCompare(d2.name)
}
})
store.replaceState({
const mainStore = useMainStore(pinia)
mainStore.$patch({
devices,
})

Expand All @@ -33,5 +38,5 @@ new View({
propsData: {
httpWarning: document.location.protocol !== 'https:',
},
store,
pinia,
}).$mount('#twofactor-webauthn-settings')
Loading
Loading