aboutsummaryrefslogtreecommitdiff
path: root/front-end/src/views/Login/components/Totp.vue
blob: 43c05d8496f15e2d138d8c0d4159fa9ca941411b (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
<template>
    <div id="totp-login-form">
        <h5>Enter your TOTP code</h5>
        <div class="flex flex-col h-32">
            <div class="h-8 mx-auto">
                <fa-icon v-if="waiting" class="animate-spin" size="xl" icon="spinner"/>
            </div>
            <div class="mx-auto mt-4">
                <VOtpInput
                    class="otp-input"
                    input-type="letter-numeric"
                    :is-disabled="waiting"
                    separator=""
                    input-classes="primary input rounded"
                    :num-inputs="6"
                    value=""
                    @on-change="onInput"
                    @on-complete="SubimitTotp"
                />
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useMessage, useWait } from '@vnuge/vnlib.browser';
import { toSafeInteger } from 'lodash-es';
import VOtpInput from "vue3-otp-input";

const emit = defineEmits(['submit'])

const { waiting } = useWait();
const { onInput } = useMessage();

const SubimitTotp = async (code : string) => {
    
    //If a request is still pending, do nothing
    if (waiting.value) {
        return
    }

    //Submit a mfa upgrade result
    emit('submit', {
        code: toSafeInteger(code)
    })
}


</script>

<style lang="scss">

#totp-login-form {
   .otp-input {
        @apply rounded-sm gap-2;

        input {
            @apply w-12 h-12 p-3 text-center text-2xl;
            appearance: none;
            -webkit-appearance: none;
        }
    }
}

</style>