From 3c41aa10ee3f383991acf525117a71eaccc385a3 Mon Sep 17 00:00:00 2001 From: Yi Yang Date: Thu, 26 Sep 2024 17:57:53 +0800 Subject: [PATCH] fix(entities-plugins): encrypted fields in credential forms (#1668) --- .../src/components/fields/FieldInput.vue | 44 ++++++++++++------- .../src/definitions/schemas/BasicAuth.ts | 2 +- .../src/definitions/schemas/KeyAuthEnc.ts | 2 +- .../src/definitions/schemas/OAuth2.ts | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/core/forms/src/components/fields/FieldInput.vue b/packages/core/forms/src/components/fields/FieldInput.vue index 765cd9e178..740d7b3653 100644 --- a/packages/core/forms/src/components/fields/FieldInput.vue +++ b/packages/core/forms/src/components/fields/FieldInput.vue @@ -17,7 +17,7 @@ :placeholder="schema.placeholder" :readonly="schema.readonly" :required="schema.required" - :type="displayInputType" + :type="inputType" :width="schema.width" @blur="onBlur" @update:model-value="onInput" @@ -26,15 +26,15 @@ v-if="schema.inputType === 'password'" #after > - - @@ -102,14 +102,7 @@ const emit = defineEmits<{ }>() const propsRefs = toRefs(props) -const eyeOpen = ref(false) - -const displayInputType = computed(() => { - if (inputType.value === 'password') { - return eyeOpen.value ? 'text' : 'password' - } - return inputType.value -}) +const masked = ref(true) const autofillSlot = inject(AUTOFILL_SLOT, undefined) @@ -129,9 +122,22 @@ defineExpose({ const inputType = computed((): string => { const iType = props.schema?.inputType.toLowerCase() - // 'string' maps to 'text' input type - // 'datetime' maps to 'datetime-local' - return iType === 'string' ? 'text' : iType === 'datetime' ? 'datetime-local' : iType || 'text' + switch (iType) { + // 'string' maps to 'text' input type + case 'string': + return 'text' + + // 'datetime' maps to 'datetime-local' + case 'datetime': + return 'datetime-local' + + // 'password' fields are masked by default, but can be toggled by the user + case 'password': + return masked.value ? 'password' : 'text' + + default: + return iType || 'text' + } }) const DATETIME_FORMATS = { @@ -196,6 +202,10 @@ const onBlur = (): void => { } } +const toggleMasked = () => { + masked.value = !masked.value +} + onMounted((): void => { // Set up debounced functions for formatting dates and numbers switch (inputType.value) { diff --git a/packages/entities/entities-plugins/src/definitions/schemas/BasicAuth.ts b/packages/entities/entities-plugins/src/definitions/schemas/BasicAuth.ts index 5ba9e018b0..fcc3df604a 100644 --- a/packages/entities/entities-plugins/src/definitions/schemas/BasicAuth.ts +++ b/packages/entities/entities-plugins/src/definitions/schemas/BasicAuth.ts @@ -8,7 +8,7 @@ export const basicAuthSchema: BasicAuthFieldSchema = { { password: { - inputType: 'text', + inputType: 'password', }, }, ], diff --git a/packages/entities/entities-plugins/src/definitions/schemas/KeyAuthEnc.ts b/packages/entities/entities-plugins/src/definitions/schemas/KeyAuthEnc.ts index 50af511140..aadfa42174 100644 --- a/packages/entities/entities-plugins/src/definitions/schemas/KeyAuthEnc.ts +++ b/packages/entities/entities-plugins/src/definitions/schemas/KeyAuthEnc.ts @@ -5,7 +5,7 @@ export default { submitWhenNull: false, hint: `You can optionally set your own unique key to authenticate the client. If missing, it will be generated for you.`, - inputType: 'text', + inputType: 'password', encrypted: true, }, }, diff --git a/packages/entities/entities-plugins/src/definitions/schemas/OAuth2.ts b/packages/entities/entities-plugins/src/definitions/schemas/OAuth2.ts index bbe27aca94..d775f31175 100644 --- a/packages/entities/entities-plugins/src/definitions/schemas/OAuth2.ts +++ b/packages/entities/entities-plugins/src/definitions/schemas/OAuth2.ts @@ -18,7 +18,7 @@ export default { submitWhenNull: false, hint: `You can optionally set your own unique client_secret. If missing, it will be generated for you.`, - inputType: 'text', + inputType: 'password', encrypted: true, }, },