feat: suite de tiendas, sync reactivo, bitácora de errores y alertas whatsapp
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -9,6 +9,9 @@ class DbSeeder {
|
||||
// Guardar usuario admin
|
||||
await _db.insertUsuario(MockData.vendedor, 'Microbot%');
|
||||
|
||||
// Registrar usuario demo para revisión en tiendas (acceso offline garantizado)
|
||||
await _db.insertUsuario(MockData.demoVendedor, '123456');
|
||||
|
||||
// Clientes
|
||||
for (final c in MockData.clientes) {
|
||||
await _db.insertCliente(c);
|
||||
|
||||
Reference in New Issue
Block a user