aboutsummaryrefslogtreecommitdiff
path: root/src/tools/token-generator/token-generator.tool.vue
blob: 28de83814a558223e502b841c27c2ac8d9e94bd3 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
  <div>
    <n-card>
      <n-form
        label-placement="left"
        label-width="140"
      >
        <n-space
          justify="center"
          item-style="padding: 0"
          :size="0"
        >
          <div>
            <n-form-item label="Uppercase (ABC...)">
              <n-switch v-model:value="withUppercase" />
            </n-form-item>

            <n-form-item label="Lowercase (abc...)">
              <n-switch v-model:value="withLowercase" />
            </n-form-item>
          </div>

          <div>
            <n-form-item label="Numbers (012...)">
              <n-switch v-model:value="withNumbers" />
            </n-form-item>

            <n-form-item label="Symbols (;-!...)">
              <n-switch v-model:value="withSymbols" />
            </n-form-item>
          </div>
        </n-space>
      </n-form>

      <n-form-item
        :label="`Length (${length})`"
        label-placement="left"
      >
        <n-slider
          v-model:value="length"
          :step="1"
          :min="1"
          :max="512"
        />
      </n-form-item>

      <n-input
        v-model:value="token"
        style="text-align: center;"
        type="textarea"
        placeholder="The token..."
        :autosize="{ minRows: 1 }"
        readonly
        autocomplete="off"
        autocorrect="off"
        autocapitalize="off"
        spellcheck="false"
      />
      <br>
      <br>
      <n-space justify="center">
        <n-button
          secondary
          autofocus
          @click="copy"
        >
          Copy
        </n-button>
        <n-button
          secondary
          @click="refreshToken"
        >
          Refresh
        </n-button>
      </n-space>
    </n-card>
  </div>
</template>

<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { ref, watch } from 'vue';
import { createToken } from './token-generator.service';


const token = ref('')
const length = ref(64)
const { copy } = useCopy({ source: token, text: 'Token copied to the clipboard' })

const withUppercase = ref(true)
const withLowercase = ref(true)
const withNumbers = ref(true)
const withSymbols = ref(false)

watch([withUppercase, withLowercase, withNumbers, withSymbols, length], refreshToken)

function refreshToken() {
    token.value = createToken({
        length: length.value,
        withUppercase: withUppercase.value,
        withLowercase: withLowercase.value,
        withNumbers: withNumbers.value,
        withSymbols: withSymbols.value,
    })
}

refreshToken()
</script>

<style lang="less" scoped>
</style>