summaryrefslogtreecommitdiff
path: root/src/client/pages/my-settings/api.vue
blob: 44f099ea1d63f68b9afdba478f32e1e1235c66ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
<section class="_card">
	<div class="_title"><fa :icon="faKey"/> API</div>
	<div class="_content">
		<mk-button @click="generateToken">{{ $t('generateAccessToken') }}</mk-button>
		<mk-button @click="regenerateToken"><fa :icon="faSyncAlt"/> {{ $t('regenerate') }}</mk-button>
	</div>
</section>
</template>

<script lang="ts">
import Vue from 'vue';
import { faKey, faSyncAlt } from '@fortawesome/free-solid-svg-icons';
import MkButton from '../../components/ui/button.vue';
import MkInput from '../../components/ui/input.vue';

export default Vue.extend({
	components: {
		MkButton, MkInput
	},
	data() {
		return {
			faKey, faSyncAlt
		};
	},
	methods: {
		async generateToken() {
			this.$root.new(await import('../../components/token-generate-window.vue').then(m => m.default), {
			}).$on('ok', async ({ name, permissions }) => {
				const { token } = await this.$root.api('miauth/gen-token', {
					session: null,
					name: name,
					permission: permissions,
				});

				this.$root.dialog({
					type: 'success',
					title: this.$t('token'),
					text: token
				});
			});
		},
		regenerateToken() {
			this.$root.dialog({
				title: this.$t('password'),
				input: {
					type: 'password'
				}
			}).then(({ canceled, result: password }) => {
				if (canceled) return;
				this.$root.api('i/regenerate_token', {
					password: password
				});
			});
		},
	}
});
</script>