Compare commits

...

21 Commits

Author SHA1 Message Date
kolaente ef69fd28b2
chore: use .then instead of await 2021-12-26 11:56:59 +01:00
kolaente e08c3a3594
chore: directly use newToken.value 2021-12-26 11:54:27 +01:00
kolaente 6063c03c2f
chore: rename to useTokens 2021-12-26 11:43:15 +01:00
kolaente 1c9f2b53ec
chore: use h5 2021-12-26 11:36:54 +01:00
kolaente dd9dbc0103
chore: return new model instead of modifying the existing 2021-12-26 11:34:36 +01:00
kolaente 7d43bbad4e
chore: fix CalDAV casing 2021-12-26 11:32:24 +01:00
kolaente e57615c020
chore: move success message after state changes 2021-12-26 11:30:44 +01:00
kolaente 9820fcba31
Merge branch 'main' into feature/caldav-tokens 2021-12-26 11:30:12 +01:00
kolaente 2d71897581
chore: use function statements everywhere 2021-12-20 18:39:01 +01:00
kolaente 5106be028c
chore: check for no results 2021-12-20 18:32:57 +01:00
kolaente 92238df2d5
fix: type 2021-12-20 18:32:32 +01:00
kolaente 9c4585bf1d
Merge branch 'main' into feature/caldav-tokens 2021-12-20 18:30:08 +01:00
kolaente 2405f958b1
fix: lint 2021-12-14 21:39:16 +01:00
kolaente e4af8a950a
chore: extract getting all tokens into a composable 2021-12-14 21:36:42 +01:00
kolaente e2fc5e940d
chore: make server functions async 2021-12-14 21:31:25 +01:00
kolaente c49fd997d2
chore: use findIndex to remove caldav token 2021-12-14 21:30:01 +01:00
kolaente 4f7a78b432
chore: use ts for caldav component 2021-12-14 21:27:16 +01:00
kolaente 79dd9ac30e
chore: clarify token is required for non-local users 2021-12-12 18:39:17 +01:00
kolaente 700691ef33
chore: put action buttons right 2021-12-12 18:32:32 +01:00
kolaente 5432981f58
feat: manage tokens 2021-12-12 18:28:14 +01:00
kolaente 6404f475ff
chore: move to script setup 2021-12-12 18:01:51 +01:00
4 changed files with 145 additions and 30 deletions

View File

@ -95,9 +95,16 @@
"disableSuccess": "Two factor authentication was sucessfully disabled."
},
"caldav": {
"title": "Caldav",
"howTo": "You can connect Vikunja to caldav clients to view and manage all tasks from different clients. Enter this url into your client:",
"more": "More information about caldav in Vikunja"
"title": "CalDAV",
"howTo": "You can connect Vikunja to CalDAV clients to view and manage all tasks from different clients. Enter this url into your client:",
"more": "More information about CalDAV in Vikunja",
"tokens": "CalDAV Tokens",
"tokensHowTo": "You can use a CalDAV token to use instead of a password to log in the above endpoint.",
"createToken": "Create a token",
"tokenCreated": "Here is your token: {token}",
"wontSeeItAgain": "Write it down, you won't be able to see it again.",
"mustUseToken": "You need to create a CalDAV token if you want to use CalDAV with a third party client. Use the token as the password.",
"usernameIs": "Your username is: {0}"
},
"avatar": {
"title": "Avatar",
@ -476,7 +483,10 @@
"showMenu": "Show the menu",
"hideMenu": "Hide the menu",
"forExample": "For example:",
"welcomeBack": "Welcome Back!"
"welcomeBack": "Welcome Back!",
"id": "ID",
"created": "Created at",
"actions": "Actions"
},
"input": {
"resetColor": "Reset Color",

15
src/models/caldavToken.js Normal file
View File

@ -0,0 +1,15 @@
import AbstractModel from './abstractModel'
export default class CaldavTokenModel extends AbstractModel {
constructor(data) {
super(data)
this.created = new Date(this.created)
}
defaults() {
return {
id: 0,
created: null,
}
}
}

View File

@ -0,0 +1,25 @@
import {formatISO} from 'date-fns'
import CaldavTokenModel from '../models/caldavToken'
import AbstractService from './abstractService'
export default class CaldavTokenService extends AbstractService {
constructor() {
super({
getAll: '/user/settings/token/caldav',
create: '/user/settings/token/caldav',
delete: '/user/settings/token/caldav/{id}',
})
}
processModel(model) {
return {
...model,
created: formatISO(new Date(model.created)),
}
}
modelFactory(data) {
return new CaldavTokenModel(data)
}
}

View File

@ -16,40 +16,105 @@
/>
</div>
</div>
<h5 class="mt-5 mb-4 has-text-weight-bold">
{{ $t('user.settings.caldav.tokens') }}
</h5>
<p>
<a href="https://vikunja.io/docs/caldav/" rel="noreferrer noopener nofollow" target="_blank">
{{ isLocalUser ? $t('user.settings.caldav.tokensHowTo') : $t('user.settings.caldav.mustUseToken') }}
<template v-if="!isLocalUser">
<br/>
<i18n-t keypath="user.settings.caldav.usernameIs">
<strong>{{ username }}</strong>
</i18n-t>
</template>
</p>
<table class="table" v-if="tokens.length > 0">
<tr>
<th>{{ $t('misc.id') }}</th>
<th>{{ $t('misc.created') }}</th>
<th class="has-text-right">{{ $t('misc.actions') }}</th>
</tr>
<tr v-for="tk in tokens" :key="tk.id">
<td>{{ tk.id }}</td>
<td>{{ formatDateShort(tk.created) }}</td>
<td class="has-text-right">
<x-button type="secondary" @click="deleteToken(tk)">
{{ $t('misc.delete') }}
</x-button>
</td>
</tr>
</table>
<Message v-if="newToken" class="mb-4">
{{ $t('user.settings.caldav.tokenCreated', {token: newToken.token}) }}<br/>
{{ $t('user.settings.caldav.wontSeeItAgain') }}
</Message>
<x-button icon="plus" class="mb-4" @click="createToken" :loading="service.loading">
{{ $t('user.settings.caldav.createToken') }}
</x-button>
<p>
<a :href="CALDAV_DOCS" rel="noreferrer noopener nofollow" target="_blank">
{{ $t('user.settings.caldav.more') }}
</a>
</p>
</card>
</template>
<script>
<script lang="ts" setup>
import copy from 'copy-to-clipboard'
import {mapState} from 'vuex'
import {CALDAV_DOCS} from '@/urls'
import {computed, ref} from 'vue'
import {useI18n} from 'vue-i18n'
import {useStore} from 'vuex'
export default {
name: 'user-settings-caldav',
data() {
return {
caldavDocsUrl: CALDAV_DOCS,
}
},
mounted() {
this.setTitle(`${this.$t('user.settings.caldav.title')} - ${this.$t('user.settings.title')}`)
},
computed: {
caldavUrl() {
return `${this.$store.getters['config/apiBase']}/dav/principals/${this.userInfo.username}/`
},
...mapState('config', ['caldavEnabled']),
...mapState({
userInfo: state => state.auth.info,
}),
},
methods: {
copy,
},
import {CALDAV_DOCS} from '@/urls'
import {useTitle} from '@/composables/useTitle'
import {success} from '@/message'
import Message from '@/components/misc/message.vue'
import CaldavTokenService from '@/services/caldavToken'
import CaldavTokenModel from '@/models/caldavToken'
const service = new CaldavTokenService()
function useTokens(): ref<CaldavTokenModel[]> {
const tokens = ref<CaldavTokenModel[]>([])
service.getAll()
.then((t: CaldavTokenModel[]) => {
tokens.value = t
})
return tokens
}
const tokens = useTokens()
const store = useStore()
const {t} = useI18n()
useTitle(() => `${t('user.settings.caldav.title')} - ${t('user.settings.title')}`)
const caldavUrl = computed(() => `${store.getters['config/apiBase']}/dav/principals/${store.state.auth.info.username}/`)
const caldavEnabled = computed(() => store.state.config.caldavEnabled)
const isLocalUser = computed(() => store.state.auth.info?.isLocalUser)
const username = computed(() => store.state.auth.info?.username)
const newToken = ref(null)
async function createToken() {
newToken.value = await service.create({})
tokens.value.push(newToken.value)
}
async function deleteToken(token: CaldavTokenModel) {
const r = await service.delete(token)
const i = tokens.value.findIndex(v => v.id === token.id)
if (i === -1) {
return
}
tokens.value.splice(i, 1)
success(r)
}
</script>