|
2 | 2 | - @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> |
3 | 3 | - |
4 | 4 | - @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> |
| 5 | + - @author Ferdinand Thiessen <opensource@fthiessen.de> |
5 | 6 | - |
6 | 7 | - @license GNU AGPL version 3 or any later version |
7 | 8 | - |
|
25 | 26 | <p class="settings-hint hidden-when-empty"> |
26 | 27 | {{ t('settings', 'Web, desktop and mobile clients currently logged in to your account.') }} |
27 | 28 | </p> |
28 | | - <AuthTokenList :tokens="tokens" |
29 | | - @toggle-scope="toggleTokenScope" |
30 | | - @rename="rename" |
31 | | - @delete="deleteToken" |
32 | | - @wipe="wipeToken" /> |
33 | | - <AuthTokenSetupDialogue v-if="canCreateToken" :add="addNewToken" /> |
| 29 | + <AuthTokenList /> |
| 30 | + <AuthTokenSetup v-if="canCreateToken" /> |
34 | 31 | </div> |
35 | 32 | </template> |
36 | 33 |
|
37 | | -<script> |
38 | | -import axios from '@nextcloud/axios' |
39 | | -import { confirmPassword } from '@nextcloud/password-confirmation' |
40 | | -import '@nextcloud/password-confirmation/dist/style.css' |
41 | | -import { generateUrl } from '@nextcloud/router' |
| 34 | +<script lang="ts"> |
| 35 | +import { loadState } from '@nextcloud/initial-state' |
| 36 | +import { translate as t } from '@nextcloud/l10n' |
| 37 | +import { defineComponent } from 'vue' |
42 | 38 |
|
43 | 39 | import AuthTokenList from './AuthTokenList.vue' |
44 | | -import AuthTokenSetupDialogue from './AuthTokenSetupDialogue.vue' |
| 40 | +import AuthTokenSetup from './AuthTokenSetup.vue' |
45 | 41 |
|
46 | | -const confirm = () => { |
47 | | - return new Promise(resolve => { |
48 | | - OC.dialogs.confirm( |
49 | | - t('settings', 'Do you really want to wipe your data from this device?'), |
50 | | - t('settings', 'Confirm wipe'), |
51 | | - resolve, |
52 | | - true, |
53 | | - ) |
54 | | - }) |
55 | | -} |
56 | | -
|
57 | | -/** |
58 | | - * Tap into a promise without losing the value |
59 | | - * |
60 | | - * @param {Function} cb the callback |
61 | | - * @return {any} val the value |
62 | | - */ |
63 | | -const tap = cb => val => { |
64 | | - cb(val) |
65 | | - return val |
66 | | -} |
67 | | -
|
68 | | -export default { |
| 42 | +export default defineComponent({ |
69 | 43 | name: 'AuthTokenSection', |
70 | 44 | components: { |
71 | | - AuthTokenSetupDialogue, |
72 | 45 | AuthTokenList, |
73 | | - }, |
74 | | - props: { |
75 | | - tokens: { |
76 | | - type: Array, |
77 | | - required: true, |
78 | | - }, |
79 | | - canCreateToken: { |
80 | | - type: Boolean, |
81 | | - required: true, |
82 | | - }, |
| 46 | + AuthTokenSetup, |
83 | 47 | }, |
84 | 48 | data() { |
85 | 49 | return { |
86 | | - baseUrl: generateUrl('/settings/personal/authtokens'), |
| 50 | + canCreateToken: loadState('settings', 'can_create_app_token'), |
87 | 51 | } |
88 | 52 | }, |
89 | 53 | methods: { |
90 | | - addNewToken(name) { |
91 | | - console.debug('creating a new app token', name) |
92 | | -
|
93 | | - const data = { |
94 | | - name, |
95 | | - } |
96 | | - return axios.post(this.baseUrl, data) |
97 | | - .then(resp => resp.data) |
98 | | - .then(tap(() => console.debug('app token created'))) |
99 | | - // eslint-disable-next-line vue/no-mutating-props |
100 | | - .then(tap(data => this.tokens.push(data.deviceToken))) |
101 | | - .catch(err => { |
102 | | - console.error.bind('could not create app password', err) |
103 | | - OC.Notification.showTemporary(t('settings', 'Error while creating device token')) |
104 | | - throw err |
105 | | - }) |
106 | | - }, |
107 | | - toggleTokenScope(token, scope, value) { |
108 | | - console.debug('updating app token scope', token.id, scope, value) |
109 | | -
|
110 | | - const oldVal = token.scope[scope] |
111 | | - token.scope[scope] = value |
112 | | -
|
113 | | - return this.updateToken(token) |
114 | | - .then(tap(() => console.debug('app token scope updated'))) |
115 | | - .catch(err => { |
116 | | - console.error.bind('could not update app token scope', err) |
117 | | - OC.Notification.showTemporary(t('settings', 'Error while updating device token scope')) |
118 | | -
|
119 | | - // Restore |
120 | | - token.scope[scope] = oldVal |
121 | | -
|
122 | | - throw err |
123 | | - }) |
124 | | - }, |
125 | | - rename(token, newName) { |
126 | | - console.debug('renaming app token', token.id, token.name, newName) |
127 | | -
|
128 | | - const oldName = token.name |
129 | | - token.name = newName |
130 | | -
|
131 | | - return this.updateToken(token) |
132 | | - .then(tap(() => console.debug('app token name updated'))) |
133 | | - .catch(err => { |
134 | | - console.error.bind('could not update app token name', err) |
135 | | - OC.Notification.showTemporary(t('settings', 'Error while updating device token name')) |
136 | | -
|
137 | | - // Restore |
138 | | - token.name = oldName |
139 | | - }) |
140 | | - }, |
141 | | - updateToken(token) { |
142 | | - return axios.put(this.baseUrl + '/' + token.id, token) |
143 | | - .then(resp => resp.data) |
144 | | - }, |
145 | | - deleteToken(token) { |
146 | | - console.debug('deleting app token', token) |
147 | | -
|
148 | | - // eslint-disable-next-line vue/no-mutating-props |
149 | | - this.tokens = this.tokens.filter(t => t !== token) |
150 | | -
|
151 | | - return axios.delete(this.baseUrl + '/' + token.id) |
152 | | - .then(resp => resp.data) |
153 | | - .then(tap(() => console.debug('app token deleted'))) |
154 | | - .catch(err => { |
155 | | - console.error.bind('could not delete app token', err) |
156 | | - OC.Notification.showTemporary(t('settings', 'Error while deleting the token')) |
157 | | -
|
158 | | - // Restore |
159 | | - // eslint-disable-next-line vue/no-mutating-props |
160 | | - this.tokens.push(token) |
161 | | - }) |
162 | | - }, |
163 | | - async wipeToken(token) { |
164 | | - console.debug('wiping app token', token) |
165 | | -
|
166 | | - try { |
167 | | - await confirmPassword() |
168 | | -
|
169 | | - if (!(await confirm())) { |
170 | | - console.debug('wipe aborted by user') |
171 | | - return |
172 | | - } |
173 | | - await axios.post(this.baseUrl + '/wipe/' + token.id) |
174 | | - console.debug('app token marked for wipe') |
175 | | -
|
176 | | - token.type = 2 |
177 | | - } catch (err) { |
178 | | - console.error('could not wipe app token', err) |
179 | | - OC.Notification.showTemporary(t('settings', 'Error while wiping the device with the token')) |
180 | | - } |
181 | | - }, |
| 54 | + t, |
182 | 55 | }, |
183 | | -} |
| 56 | +}) |
184 | 57 | </script> |
185 | | - |
186 | | -<style scoped> |
187 | | -
|
188 | | -</style> |
0 commit comments