feat: suite de tiendas, sync reactivo, bitácora de errores y alertas whatsapp

This commit is contained in:
Pablinux
2026-11-22 17:41:18 -05:00
parent cc4ab12d1d
commit 6a5ebb907d
76 changed files with 2975 additions and 312 deletions
+17 -3
View File
@@ -182,13 +182,16 @@ class DatabaseHelper {
Future<Map<String, dynamic>?> loginUsuario(String email, String password) async {
final db = await database;
// Acepta hash SHA-256 o texto plano (compatibilidad con seeder viejo)
// Soporte para autenticación flexible (email o id/usuario) insensible a mayúsculas
final cleanEmail = email.trim().toLowerCase();
final hash = _sha256(password);
var rows = await db.query('usuarios',
where: 'email = ? AND password = ?', whereArgs: [email, hash]);
where: '(LOWER(email) = ? OR LOWER(id) = ?) AND password = ?',
whereArgs: [cleanEmail, cleanEmail, hash]);
if (rows.isEmpty) {
rows = await db.query('usuarios',
where: 'email = ? AND password = ?', whereArgs: [email, password]);
where: '(LOWER(email) = ? OR LOWER(id) = ?) AND password = ?',
whereArgs: [cleanEmail, cleanEmail, password]);
}
return rows.isEmpty ? null : rows.first;
}
@@ -199,6 +202,17 @@ class DatabaseHelper {
return rows.isEmpty ? null : Vendedor.fromMap(rows.first);
}
// Actualiza el número telefónico del usuario en SQLite local (para alertas de WhatsApp)
Future<void> updateUsuarioTelefono(String usuarioId, String telefono) async {
final db = await database;
await db.update(
'usuarios',
{'telefono': telefono},
where: 'id = ? OR email = ?',
whereArgs: [usuarioId, usuarioId],
);
}
// ── Clientes ────────────────────────────────────────────────
Future<List<Cliente>> getClientes() async {