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})`
|
||||
})
|
||||
|
||||
return searchEntries[0]?.dn
|
||||
const userDN = searchEntries[0]?.dn
|
||||
|
||||
if (!userDN) throw new InvalidCredentialsError('Usuário não encontrado')
|
||||
|
||||
return userDN
|
||||
} catch (err) {
|
||||
console.error('Error finding user:', err)
|
||||
throw err
|
||||
} finally {
|
||||
await ldapClient.unbind()
|
||||
}
|
||||
|
||||
throw new Error('User not found')
|
||||
}
|
||||
|
||||
export async function updatePassword({
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="font-weight-light mb-2">Regras para a nova senha:</div>
|
||||
<v-alert
|
||||
v-for="alert in alerts"
|
||||
:key="alert.text"
|
||||
:type="alertType(password, alert.rule)"
|
||||
class="mb-2 rule"
|
||||
variant="tonal"
|
||||
variant="plain"
|
||||
density="compact"
|
||||
:text="alert.text"
|
||||
/>
|
||||
|
@ -26,19 +25,23 @@ function alertType(password: string, rule: (password: string) => boolean) {
|
|||
|
||||
const alerts = [
|
||||
{
|
||||
text: 'Uma ou mais letras minúsculas.',
|
||||
text: 'Ao menos uma letra minúscula.',
|
||||
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)
|
||||
},
|
||||
{
|
||||
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
|
||||
},
|
||||
{
|
||||
text: `Um ou mais caracteres especiais (!"#$%&'()*+,\\-./:;<=>?@[]^_\`{}|~).`,
|
||||
text: `Ao menos um símbolo especiai (!"#$%&'()*+,\\-./:;<=>?@[]^_\`{}|~).`,
|
||||
rule: (password: string) =>
|
||||
/[●!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/.test(password)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,15 @@
|
|||
<v-row justify="center">
|
||||
<v-col xl="5" lg="6" md="7" sm="10">
|
||||
<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" />
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
@ -17,6 +26,8 @@ import { trpc } from '../trpc'
|
|||
|
||||
const loading = ref(false)
|
||||
|
||||
const errorMsg = ref('')
|
||||
|
||||
async function handleSubmit({
|
||||
username,
|
||||
currentPassword,
|
||||
|
@ -28,13 +39,17 @@ async function handleSubmit({
|
|||
}) {
|
||||
try {
|
||||
loading.value = true
|
||||
errorMsg.value = ''
|
||||
|
||||
await trpc.updatePassword.mutate({
|
||||
username,
|
||||
currentPassword,
|
||||
newPassword
|
||||
})
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error)
|
||||
|
||||
errorMsg.value = error.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user