adição de recuperação de senha e limpeza de remanescentes

This commit is contained in:
joao.herculano
2026-08-06 11:53:09 -03:00
parent 4e1ebe861c
commit 5b10e46e62
20 changed files with 183 additions and 925 deletions
+44
View File
@@ -255,6 +255,50 @@ export const criarConta = createServerFn({ method: "POST" })
};
});
export const recuperarSenha = createServerFn({ method: "POST" })
.validator(loginSchema)
.handler(async ({ data }) => {
const nome = normalizarNome(data.nome);
const [{ getPool, sql }, bcrypt] = await Promise.all([
import("@/lib/db.server"),
import("bcryptjs"),
]);
const pool = await getPool();
const existente = await pool
.request()
.input("nome", sql.NVarChar(150), nome)
.query<{ id: string; ativo: boolean }>(`
SELECT TOP 1 id, ativo
FROM slalog.usuarios
WHERE LOWER(nome) = LOWER(@nome)
`);
const usuario = existente.recordset[0];
if (!usuario || !usuario.ativo) {
throw new Error("Nome de usuário não encontrado.");
}
const senhaHash = await bcrypt.hash(data.senha, 10);
await pool
.request()
.input("id", sql.UniqueIdentifier, usuario.id)
.input("senhaHash", sql.NVarChar(255), senhaHash)
.query(`
UPDATE slalog.usuarios
SET senha_hash = @senhaHash,
aprovado = 0,
updated_at = SYSDATETIME()
WHERE id = @id
`);
const { clearAuthSession } = await import("@/lib/auth.server");
await clearAuthSession();
return { success: true };
});
export const sair = createServerFn({ method: "POST" }).handler(async () => {
const { clearAuthSession } = await import("@/lib/auth.server");
await clearAuthSession();