aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/views/Login/pki/index.vue
blob: 8edd0632e6bbfe76612e44ff63108d7251866fa3 (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
59
60
61
62
63
64
65
66
67
<script setup lang="ts">
import { isEmpty } from 'lodash-es';
import { apiCall, debugLog, useMessage } from '@vnuge/vnlib.browser';
import { ref } from 'vue'
import { decodeJwt } from 'jose'
import { useRouter } from 'vue-router';
import { useStore } from '../../../store';

const { setMessage } = useMessage()
const { push } = useRouter()
const store = useStore()

const otp = ref('')

const submit = () => {

    apiCall(async () => {
        if (isEmpty(otp.value)) {
            setMessage('Please enter your OTP')
            return
        }

        //try to decode the jwt to confirm its form is valid
        const jwt = decodeJwt(otp.value)
        debugLog(jwt)

        await store.pki!.pkiAuth.login(otp.value)

        //Go back to login page
        push({ name: 'Login' })
    })
}

</script>

<template>
    <div id="pki-login-template" class="app-component-entry">
        <div class="container max-w-lg mx-auto mt-6 lg:mt-20">
            <div class="p-2 text-center bg-white border rounded shadow-md dark:border-dark-500 dark:bg-dark-800">
                
                <h4>Enter your PKI-OTP</h4>

                <div class="p-3">
                    <div class="">
                        <textarea v-model="otp" class="w-full p-1 border rounded-sm input primary" rows="5"></textarea>
                    </div>

                    <div class="flex justify-between mt-4">
                        <div class="text-sm">
                            <a class="link" target="_blank" href="https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Plugins.Essentials.Accounts">
                                Goto OTP spec
                                <fa-icon icon="arrow-right" class="ml-1" />
                            </a>
                        </div>
                        <div class="button-group">
                            <RouterLink to="/login">
                                <button class="btn">Back</button>
                            </RouterLink>
                            <button class="btn primary" @click.prevent="submit">Login</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</template>