mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
FE support for https://github.com/chatwoot/chatwoot/pull/12290 ## Linear: - https://github.com/chatwoot/chatwoot/issues/486 ## Description This PR implements Multi-Factor Authentication (MFA) support for user accounts, enhancing security by requiring a second form of verification during login. The feature adds TOTP (Time-based One-Time Password) authentication with QR code generation and backup codes for account recovery. ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Added comprehensive RSpec tests for MFA controller functionality - Tested MFA setup flow with QR code generation - Verified OTP validation and backup code generation - Tested login flow with MFA enabled/disabled ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
155 lines
4.4 KiB
Vue
155 lines
4.4 KiB
Vue
<script setup>
|
|
import { computed, ref, onMounted, nextTick, getCurrentInstance } from 'vue';
|
|
const props = defineProps({
|
|
modelValue: { type: [String, Number], default: '' },
|
|
type: { type: String, default: 'text' },
|
|
customInputClass: { type: [String, Object, Array], default: '' },
|
|
placeholder: { type: String, default: '' },
|
|
label: { type: String, default: '' },
|
|
id: { type: String, default: '' },
|
|
size: {
|
|
type: String,
|
|
default: 'md',
|
|
validator: value => ['sm', 'md'].includes(value),
|
|
},
|
|
message: { type: String, default: '' },
|
|
disabled: { type: Boolean, default: false },
|
|
messageType: {
|
|
type: String,
|
|
default: 'info',
|
|
validator: value => ['info', 'error', 'success'].includes(value),
|
|
},
|
|
min: { type: String, default: '' },
|
|
max: { type: String, default: '' },
|
|
autofocus: { type: Boolean, default: false },
|
|
});
|
|
|
|
const emit = defineEmits([
|
|
'update:modelValue',
|
|
'blur',
|
|
'input',
|
|
'focus',
|
|
'enter',
|
|
]);
|
|
|
|
// Generate a unique ID per component instance when `id` prop is not provided.
|
|
const { uid } = getCurrentInstance();
|
|
const uniqueId = computed(() => props.id || `input-${uid}`);
|
|
|
|
const isFocused = ref(false);
|
|
const inputRef = ref(null);
|
|
|
|
const messageClass = computed(() => {
|
|
switch (props.messageType) {
|
|
case 'error':
|
|
return 'text-n-ruby-9 dark:text-n-ruby-9';
|
|
case 'success':
|
|
return 'text-n-teal-10 dark:text-n-teal-10';
|
|
default:
|
|
return 'text-n-slate-11 dark:text-n-slate-11';
|
|
}
|
|
});
|
|
|
|
const inputOutlineClass = computed(() => {
|
|
switch (props.messageType) {
|
|
case 'error':
|
|
return 'outline-n-ruby-8 dark:outline-n-ruby-8 hover:outline-n-ruby-9 dark:hover:outline-n-ruby-9 disabled:outline-n-ruby-8 dark:disabled:outline-n-ruby-8';
|
|
default:
|
|
return 'outline-n-weak dark:outline-n-weak hover:outline-n-slate-6 dark:hover:outline-n-slate-6 disabled:outline-n-weak dark:disabled:outline-n-weak focus:outline-n-brand dark:focus:outline-n-brand';
|
|
}
|
|
});
|
|
|
|
const handleInput = event => {
|
|
let value = event.target.value;
|
|
// Convert to number if type is number and value is not empty
|
|
if (props.type === 'number' && value !== '') {
|
|
value = Number(value);
|
|
}
|
|
emit('update:modelValue', value);
|
|
emit('input', event);
|
|
};
|
|
|
|
const handleFocus = event => {
|
|
emit('focus', event);
|
|
isFocused.value = true;
|
|
};
|
|
|
|
const sizeClass = computed(() => {
|
|
switch (props.size) {
|
|
case 'sm':
|
|
return 'h-8 !px-3 !py-2';
|
|
case 'md':
|
|
return 'h-10 !px-3 !py-2.5';
|
|
default:
|
|
return 'h-10 !px-3 !py-2.5';
|
|
}
|
|
});
|
|
|
|
const handleBlur = event => {
|
|
emit('blur', event);
|
|
isFocused.value = false;
|
|
};
|
|
|
|
const handleEnter = event => {
|
|
emit('enter', event);
|
|
};
|
|
|
|
onMounted(() => {
|
|
if (props.autofocus) {
|
|
nextTick(() => {
|
|
inputRef.value?.focus();
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="relative flex flex-col min-w-0 gap-1">
|
|
<label
|
|
v-if="label"
|
|
:for="uniqueId"
|
|
class="mb-0.5 text-sm font-medium text-n-slate-12"
|
|
>
|
|
{{ label }}
|
|
</label>
|
|
<!-- Added prefix slot to allow adding icons to the input -->
|
|
<slot name="prefix" />
|
|
<input
|
|
:id="uniqueId"
|
|
v-bind="$attrs"
|
|
ref="inputRef"
|
|
:value="modelValue"
|
|
:class="[
|
|
customInputClass,
|
|
inputOutlineClass,
|
|
sizeClass,
|
|
{
|
|
error: messageType === 'error',
|
|
focus: isFocused,
|
|
},
|
|
]"
|
|
:type="type"
|
|
:placeholder="placeholder"
|
|
:disabled="disabled"
|
|
:min="['date', 'datetime-local', 'time'].includes(type) ? min : undefined"
|
|
:max="
|
|
['date', 'datetime-local', 'time', 'number'].includes(type)
|
|
? max
|
|
: undefined
|
|
"
|
|
class="block w-full reset-base text-sm !mb-0 outline outline-1 border-none border-0 outline-offset-[-1px] rounded-lg bg-n-alpha-black2 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-n-slate-10 dark:placeholder:text-n-slate-10 disabled:cursor-not-allowed disabled:opacity-50 text-n-slate-12 transition-all duration-500 ease-in-out [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"
|
|
@input="handleInput"
|
|
@focus="handleFocus"
|
|
@blur="handleBlur"
|
|
@keyup.enter="handleEnter"
|
|
/>
|
|
<p
|
|
v-if="message"
|
|
class="min-w-0 mt-1 mb-0 text-xs truncate transition-all duration-500 ease-in-out"
|
|
:class="messageClass"
|
|
>
|
|
{{ message }}
|
|
</p>
|
|
</div>
|
|
</template>
|