Fix user not found error and update password validation messages
This commit is contained in:
parent
e02d0e37c4
commit
98590b773e
|
@ -27,14 +27,17 @@ async function getUserDN(username: string): Promise<string> {
|
||||||
filter: `(sAMAccountName=${username})`
|
filter: `(sAMAccountName=${username})`
|
||||||
})
|
})
|
||||||
|
|
||||||
return searchEntries[0]?.dn
|
const userDN = searchEntries[0]?.dn
|
||||||
|
|
||||||
|
if (!userDN) throw new InvalidCredentialsError('Usuário não encontrado')
|
||||||
|
|
||||||
|
return userDN
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error finding user:', err)
|
console.error('Error finding user:', err)
|
||||||
|
throw err
|
||||||
} finally {
|
} finally {
|
||||||
await ldapClient.unbind()
|
await ldapClient.unbind()
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('User not found')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updatePassword({
|
export async function updatePassword({
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="font-weight-light mb-2">Regras para a nova senha:</div>
|
|
||||||
<v-alert
|
<v-alert
|
||||||
v-for="alert in alerts"
|
v-for="alert in alerts"
|
||||||
:key="alert.text"
|
:key="alert.text"
|
||||||
:type="alertType(password, alert.rule)"
|
:type="alertType(password, alert.rule)"
|
||||||
class="mb-2 rule"
|
class="mb-2 rule"
|
||||||
variant="tonal"
|
variant="plain"
|
||||||
density="compact"
|
density="compact"
|
||||||
:text="alert.text"
|
:text="alert.text"
|
||||||
/>
|
/>
|
||||||
|
@ -26,19 +25,23 @@ function alertType(password: string, rule: (password: string) => boolean) {
|
||||||
|
|
||||||
const alerts = [
|
const alerts = [
|
||||||
{
|
{
|
||||||
text: 'Uma ou mais letras minúsculas.',
|
text: 'Ao menos uma letra minúscula.',
|
||||||
rule: (password: string) => /[a-z]/.test(password)
|
rule: (password: string) => /[a-z]/.test(password)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: 'Uma ou mais letras maiúsculas.',
|
text: 'Ao menos uma letra maiúsculas.',
|
||||||
rule: (password: string) => /[A-Z]/.test(password)
|
rule: (password: string) => /[A-Z]/.test(password)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '8 ou mais caracteres.',
|
text: 'Ao manos um número.',
|
||||||
|
rule: (password: string) => /\d/.test(password)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Ter 8 ou mais caracteres de comprimento.',
|
||||||
rule: (password: string) => password.length >= 8
|
rule: (password: string) => password.length >= 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: `Um ou mais caracteres especiais (!"#$%&'()*+,\\-./:;<=>?@[]^_\`{}|~).`,
|
text: `Ao menos um símbolo especiai (!"#$%&'()*+,\\-./:;<=>?@[]^_\`{}|~).`,
|
||||||
rule: (password: string) =>
|
rule: (password: string) =>
|
||||||
/[●!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/.test(password)
|
/[●!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/.test(password)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,15 @@
|
||||||
<v-row justify="center">
|
<v-row justify="center">
|
||||||
<v-col xl="5" lg="6" md="7" sm="10">
|
<v-col xl="5" lg="6" md="7" sm="10">
|
||||||
<logo class="mx-auto my-3" :style="{ maxWidth: '128px' }" />
|
<logo class="mx-auto my-3" :style="{ maxWidth: '128px' }" />
|
||||||
|
<v-alert
|
||||||
|
class="mb-2"
|
||||||
|
variant="tonal"
|
||||||
|
closable
|
||||||
|
type="error"
|
||||||
|
v-if="errorMsg"
|
||||||
|
>
|
||||||
|
{{ errorMsg }}
|
||||||
|
</v-alert>
|
||||||
<main-form @submit="handleSubmit" :loading="loading" />
|
<main-form @submit="handleSubmit" :loading="loading" />
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
@ -17,6 +26,8 @@ import { trpc } from '../trpc'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const errorMsg = ref('')
|
||||||
|
|
||||||
async function handleSubmit({
|
async function handleSubmit({
|
||||||
username,
|
username,
|
||||||
currentPassword,
|
currentPassword,
|
||||||
|
@ -28,13 +39,17 @@ async function handleSubmit({
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
errorMsg.value = ''
|
||||||
|
|
||||||
await trpc.updatePassword.mutate({
|
await trpc.updatePassword.mutate({
|
||||||
username,
|
username,
|
||||||
currentPassword,
|
currentPassword,
|
||||||
newPassword
|
newPassword
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
||||||
|
errorMsg.value = error.message
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user