Initial commit

This commit is contained in:
root
2025-12-21 10:00:41 -05:00
committed by Sebastian Krupinski
commit d2b2846567
17 changed files with 2757 additions and 0 deletions

View File

@@ -0,0 +1,267 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue';
interface User {
uid: string;
identity: string;
label: string;
provider?: string;
}
const props = defineProps<{
user: User;
}>();
const emit = defineEmits<{
update: [];
}>();
const loading = ref(false);
const statusLoading = ref(false);
const error = ref<string | null>(null);
const success = ref<string | null>(null);
const hasPassword = ref(false);
const passwordDialog = ref(false);
const removeDialog = ref(false);
const newPassword = ref('');
const confirmPassword = ref('');
const loadStatus = async () => {
statusLoading.value = true;
try {
const response = await fetch(`/m/authentication_provider_password/admin/status/${props.user.uid}`, {
credentials: 'include',
});
if (response.ok) {
const data = await response.json();
hasPassword.value = data.enrolled ?? false;
}
} catch (err) {
console.error('Failed to load password status:', err);
} finally {
statusLoading.value = false;
}
};
const resetPassword = async () => {
if (newPassword.value !== confirmPassword.value) {
error.value = 'Passwords do not match';
return;
}
if (newPassword.value.length < 8) {
error.value = 'Password must be at least 8 characters';
return;
}
loading.value = true;
error.value = null;
try {
const response = await fetch('/m/authentication_provider_password/admin/reset', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify({
uid: props.user.uid,
password: newPassword.value,
}),
});
if (response.ok) {
success.value = hasPassword.value ? 'Password reset successfully' : 'Password set successfully';
passwordDialog.value = false;
newPassword.value = '';
confirmPassword.value = '';
await loadStatus();
emit('update');
} else {
const data = await response.json();
error.value = data.error || 'Failed to reset password';
}
} catch (err: any) {
error.value = err.message || 'Failed to reset password';
} finally {
loading.value = false;
}
};
const removePassword = async () => {
loading.value = true;
error.value = null;
try {
const response = await fetch(`/m/authentication_provider_password/admin/remove/${props.user.uid}`, {
method: 'DELETE',
credentials: 'include',
});
if (response.ok) {
success.value = 'Password removed successfully';
removeDialog.value = false;
await loadStatus();
emit('update');
} else {
const data = await response.json();
error.value = data.error || 'Failed to remove password';
}
} catch (err: any) {
error.value = err.message || 'Failed to remove password';
} finally {
loading.value = false;
}
};
onMounted(() => {
loadStatus();
});
</script>
<template>
<VCard variant="outlined">
<VCardTitle class="d-flex align-center">
<VIcon icon="mdi-lock" class="mr-2" />
Password
</VCardTitle>
<VCardText>
<VAlert
v-if="error"
type="error"
closable
class="mb-4"
@click:close="error = null"
>
{{ error }}
</VAlert>
<VAlert
v-if="success"
type="success"
closable
class="mb-4"
@click:close="success = null"
>
{{ success }}
</VAlert>
<div v-if="statusLoading" class="text-center py-4">
<VProgressCircular indeterminate size="small" />
</div>
<template v-else>
<p class="mb-2">
<strong>Status:</strong>
<VChip
:color="hasPassword ? 'success' : 'grey'"
size="small"
class="ml-2"
>
{{ hasPassword ? 'Password Set' : 'No Password' }}
</VChip>
</p>
<p class="mb-4">
{{ hasPassword ? 'Reset the user\'s password. The user will be able to login with the new password immediately.' : 'Set a password for this user to enable password-based authentication.' }}
</p>
<div class="d-flex gap-2">
<VBtn
color="primary"
:disabled="user.provider === 'oidc'"
@click="passwordDialog = true"
>
{{ hasPassword ? 'Reset Password' : 'Set Password' }}
</VBtn>
<VBtn
v-if="hasPassword"
color="error"
variant="outlined"
:disabled="user.provider === 'oidc'"
@click="removeDialog = true"
>
Remove Password
</VBtn>
</div>
<div v-if="user.provider === 'oidc'" class="text-caption text-grey mt-2">
Password authentication not available for externally managed users
</div>
</template>
</VCardText>
<!-- Password Reset Dialog -->
<VDialog v-model="passwordDialog" max-width="500">
<VCard>
<VCardTitle>{{ hasPassword ? 'Reset Password' : 'Set Password' }}</VCardTitle>
<VCardText>
<VForm @submit.prevent="resetPassword">
<VTextField
v-model="newPassword"
label="New Password"
type="password"
variant="outlined"
class="mb-4"
required
hint="Minimum 8 characters"
/>
<VTextField
v-model="confirmPassword"
label="Confirm Password"
type="password"
variant="outlined"
required
:error="confirmPassword.length > 0 && confirmPassword !== newPassword"
:error-messages="confirmPassword.length > 0 && confirmPassword !== newPassword ? ['Passwords do not match'] : []"
/>
</VForm>
</VCardText>
<VCardActions>
<VSpacer />
<VBtn @click="passwordDialog = false">Cancel</VBtn>
<VBtn
color="primary"
:loading="loading"
@click="resetPassword"
>
{{ hasPassword ? 'Reset Password' : 'Set Password' }}
</VBtn>
</VCardActions>
</VCard>
</VDialog>
<!-- Remove Password Dialog -->
<VDialog v-model="removeDialog" max-width="500">
<VCard>
<VCardTitle class="d-flex align-center">
<VIcon icon="mdi-alert" color="warning" class="mr-2" />
Remove Password
</VCardTitle>
<VCardText>
<VAlert type="warning" class="mb-4">
<strong>Warning:</strong> This will remove the user's password.
They will not be able to login using password authentication.
</VAlert>
<p>
Are you sure you want to remove the password for <strong>{{ user.label }}</strong>?
</p>
</VCardText>
<VCardActions>
<VSpacer />
<VBtn @click="removeDialog = false">Cancel</VBtn>
<VBtn
color="error"
:loading="loading"
@click="removePassword"
>
Remove Password
</VBtn>
</VCardActions>
</VCard>
</VDialog>
</VCard>
</template>

View File

@@ -0,0 +1,145 @@
<script setup lang="ts">
import { ref } from 'vue';
interface User {
uid: string;
identity: string;
label: string;
}
const props = defineProps<{
user: User;
}>();
const loading = ref(false);
const error = ref<string | null>(null);
const success = ref<string | null>(null);
const password = ref('');
const confirmPassword = ref('');
const expanded = ref(false);
const setPassword = async () => {
if (password.value !== confirmPassword.value) {
error.value = 'Passwords do not match';
return;
}
if (password.value.length < 8) {
error.value = 'Password must be at least 8 characters';
return;
}
loading.value = true;
error.value = null;
try {
const response = await fetch('/m/authentication_provider_password/admin/reset', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
body: JSON.stringify({
uid: props.user.uid,
password: password.value,
}),
});
if (response.ok) {
success.value = 'Password set successfully';
password.value = '';
confirmPassword.value = '';
expanded.value = false;
} else {
const data = await response.json();
error.value = data.error || 'Failed to set password';
}
} catch (err: any) {
error.value = err.message || 'Failed to set password';
} finally {
loading.value = false;
}
};
</script>
<template>
<VExpansionPanels v-model="expanded">
<VExpansionPanel>
<VExpansionPanelTitle>
<div class="d-flex align-center">
<VIcon icon="mdi-lock" class="mr-3" />
<div>
<div class="font-weight-medium">Password Authentication</div>
<div class="text-caption text-grey">
{{ success ? 'Password configured' : 'Set a password for this user' }}
</div>
</div>
<VSpacer />
<VChip
v-if="success"
color="success"
size="small"
prepend-icon="mdi-check"
>
Configured
</VChip>
</div>
</VExpansionPanelTitle>
<VExpansionPanelText>
<VAlert
v-if="error"
type="error"
closable
class="mb-4"
@click:close="error = null"
>
{{ error }}
</VAlert>
<VAlert
v-if="success"
type="success"
closable
class="mb-4"
@click:close="success = null"
>
{{ success }}
</VAlert>
<VForm @submit.prevent="setPassword">
<VTextField
v-model="password"
label="Password"
type="password"
variant="outlined"
class="mb-4"
required
hint="Minimum 8 characters"
persistent-hint
/>
<VTextField
v-model="confirmPassword"
label="Confirm Password"
type="password"
variant="outlined"
required
:error="confirmPassword.length > 0 && confirmPassword !== password"
:error-messages="confirmPassword.length > 0 && confirmPassword !== password ? ['Passwords do not match'] : []"
/>
<div class="mt-4">
<VBtn
type="submit"
color="primary"
:loading="loading"
:disabled="success !== null"
>
Set Password
</VBtn>
</div>
</VForm>
</VExpansionPanelText>
</VExpansionPanel>
</VExpansionPanels>
</template>

32
src/integrations.ts Normal file
View File

@@ -0,0 +1,32 @@
import type { ModuleIntegrations } from '@KTXC/types/moduleTypes';
const integrations: ModuleIntegrations = {
user_settings_security: [
{
id: 'password-change',
label: 'Change Password',
priority: 10,
component: () => import('@/views/UserSettingsSecurityPanel.vue'),
},
],
user_manager_security_panels: [
{
id: 'password-management',
label: 'Password',
icon: 'mdi-lock',
priority: 10,
component: () => import('@/components/AdminSecurityPanel.vue'),
},
],
user_manager_create_credentials: [
{
id: 'password-setup',
label: 'Password',
icon: 'mdi-lock',
priority: 10,
component: () => import('@/components/CredentialSetupPanel.vue'),
},
],
};
export default integrations;

9
src/main.ts Normal file
View File

@@ -0,0 +1,9 @@
import integrations from './integrations'
export {
integrations
}
export default {
integrations
}

View File

@@ -0,0 +1,244 @@
<script setup lang="ts">
import { ref, computed } from 'vue';
const isLoading = ref(false);
const errorMessage = ref<string | null>(null);
const successMessage = ref<string | null>(null);
const currentPassword = ref('');
const newPassword = ref('');
const confirmPassword = ref('');
// Password visibility toggles
const isCurrentPasswordVisible = ref(false);
const isNewPasswordVisible = ref(false);
const isConfirmPasswordVisible = ref(false);
// Password strength and validation
const passwordRequirements = [
{
text: 'Minimum 8 characters long',
test: (password: string) => password.length >= 8
},
{
text: 'At least one lowercase character',
test: (password: string) => /[a-z]/.test(password)
},
{
text: 'At least one uppercase character',
test: (password: string) => /[A-Z]/.test(password)
},
{
text: 'At least one number',
test: (password: string) => /[0-9]/.test(password)
},
];
const passwordStrength = computed(() => {
if (!newPassword.value) return { score: 0, label: '', color: '' };
const metRequirements = passwordRequirements.filter(req => req.test(newPassword.value)).length;
const total = passwordRequirements.length;
const percentage = (metRequirements / total) * 100;
if (percentage < 50) return { score: percentage, label: 'Weak', color: 'error' };
if (percentage < 75) return { score: percentage, label: 'Fair', color: 'warning' };
if (percentage < 100) return { score: percentage, label: 'Good', color: 'info' };
return { score: percentage, label: 'Strong', color: 'success' };
});
const isFormValid = computed(() => {
return currentPassword.value.length > 0 &&
newPassword.value.length >= 8 &&
newPassword.value === confirmPassword.value &&
passwordRequirements.every(req => req.test(newPassword.value));
});
const saveChanges = async () => {
errorMessage.value = null;
successMessage.value = null;
if (!isFormValid.value) {
errorMessage.value = 'Please ensure all requirements are met.';
return;
}
if (newPassword.value !== confirmPassword.value) {
errorMessage.value = 'New passwords do not match.';
return;
}
isLoading.value = true;
try {
const response = await fetch('/m/authentication_provider_password/password/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
current_password: currentPassword.value,
new_password: newPassword.value,
}),
});
if (response.ok) {
currentPassword.value = '';
newPassword.value = '';
confirmPassword.value = '';
successMessage.value = 'Password updated successfully.';
} else {
const data = await response.json();
errorMessage.value = data.error || 'An error occurred while updating the password.';
}
} catch (error) {
errorMessage.value = 'An unexpected error occurred.';
} finally {
isLoading.value = false;
}
};
</script>
<template>
<VCol cols="12" md="8" lg="4">
<VCard title="Change Password">
<VCardText>
<VAlert
v-if="errorMessage"
type="error"
class="mb-4"
closable
@click:close="errorMessage = null"
>
{{ errorMessage }}
</VAlert>
<VAlert
v-if="successMessage"
type="success"
class="mb-4"
closable
@click:close="successMessage = null"
>
{{ successMessage }}
</VAlert>
<!-- Current Password -->
<VRow class="mb-3">
<VCol cols="12">
<VTextField
v-model="currentPassword"
:type="isCurrentPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isCurrentPasswordVisible ? 'mdi-eye-off' : 'mdi-eye'"
label="Current Password"
placeholder="············"
variant="outlined"
autocomplete="off"
@click:append-inner="isCurrentPasswordVisible = !isCurrentPasswordVisible"
/>
</VCol>
</VRow>
<!-- New Password -->
<VRow>
<VCol cols="12">
<VTextField
v-model="newPassword"
:type="isNewPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isNewPasswordVisible ? 'mdi-eye-off' : 'mdi-eye'"
label="New Password"
placeholder="············"
variant="outlined"
autocomplete="new-password"
@click:append-inner="isNewPasswordVisible = !isNewPasswordVisible"
/>
</VCol>
<VCol cols="12">
<VTextField
v-model="confirmPassword"
:type="isConfirmPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isConfirmPasswordVisible ? 'mdi-eye-off' : 'mdi-eye'"
label="Confirm New Password"
placeholder="············"
variant="outlined"
autocomplete="new-password"
:error="confirmPassword.length > 0 && confirmPassword !== newPassword"
:error-messages="confirmPassword.length > 0 && confirmPassword !== newPassword ? ['Passwords do not match'] : []"
@click:append-inner="isConfirmPasswordVisible = !isConfirmPasswordVisible"
/>
</VCol>
</VRow>
<!-- Password Strength Indicator -->
<VRow v-if="newPassword.length > 0" class="mt-2">
<VCol cols="12">
<div class="mb-2">
<div class="d-flex justify-space-between mb-1">
<span class="text-caption">Password Strength</span>
<span class="text-caption font-weight-bold" :class="`text-${passwordStrength.color}`">
{{ passwordStrength.label }}
</span>
</div>
<VProgressLinear
:model-value="passwordStrength.score"
:color="passwordStrength.color"
height="6"
rounded
/>
</div>
</VCol>
</VRow>
<!-- Password Requirements -->
<VRow class="mt-2">
<VCol cols="12">
<p class="text-base font-weight-medium mb-2">
Password Requirements:
</p>
<ul class="d-flex flex-column gap-y-2">
<li
v-for="(requirement, index) in passwordRequirements"
:key="index"
class="d-flex align-center"
>
<VIcon
:icon="newPassword.length > 0 && requirement.test(newPassword) ? 'mdi-check-circle' : 'mdi-circle-outline'"
:color="newPassword.length > 0 && requirement.test(newPassword) ? 'success' : 'grey'"
size="18"
class="me-2"
/>
<span :class="newPassword.length > 0 && requirement.test(newPassword) ? 'text-success' : ''">
{{ requirement.text }}
</span>
</li>
</ul>
</VCol>
</VRow>
<!-- Action Buttons -->
<VRow class="mt-4">
<VCol cols="12">
<VBtn
color="primary"
:disabled="!isFormValid"
:loading="isLoading"
@click="saveChanges"
>
Save Changes
</VBtn>
<VBtn
color="secondary"
variant="outlined"
class="ms-3"
:disabled="isLoading"
@click="currentPassword = ''; newPassword = ''; confirmPassword = ''; errorMessage = null; successMessage = null"
>
Reset
</VBtn>
</VCol>
</VRow>
</VCardText>
</VCard>
</VCol>
</template>