Vista información general
This commit is contained in:
@@ -32,9 +32,10 @@ function validar()
|
||||
|
||||
$emailEncrypted = encrypt($email);
|
||||
|
||||
// Obtenemos el usuario
|
||||
$sql = "SELECT id_usuario, nombre, email, password_hash, tipo_usuario, activo
|
||||
FROM usuarios_sistema
|
||||
WHERE email = ?";
|
||||
FROM usuarios_sistema WHERE email = ?";
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql, [$emailEncrypted]);
|
||||
|
||||
if ($stmt && $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
|
||||
@@ -54,6 +55,38 @@ function validar()
|
||||
|
||||
registrarBitacora($conn, $row['id_usuario'], $email, $ip, 1, 'Login exitoso');
|
||||
|
||||
// Buscar RFC y teléfono desde solicitudes_importadores
|
||||
$sqlSolicitudes = "SELECT rfc, phone FROM solicitudes_importadores WHERE email = ?";
|
||||
$stmtSolicitudes = sqlsrv_query($conn, $sqlSolicitudes, [$email]);
|
||||
|
||||
if ($stmtSolicitudes && $solRow = sqlsrv_fetch_array($stmtSolicitudes, SQLSRV_FETCH_ASSOC)) {
|
||||
// Desencriptar RFC
|
||||
$rfc = strtoupper(decrypt(trim($solRow['rfc'])));
|
||||
|
||||
// Validar teléfono (ej. 123 4567890)
|
||||
$telefono = trim($solRow['phone']);
|
||||
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
|
||||
$telefono = null; // o puedes dejarlo como ''
|
||||
}
|
||||
}
|
||||
|
||||
$nombreUsuario = decrypt($row['nombre']);
|
||||
|
||||
$sqlCheck = "SELECT COUNT(*) AS total FROM informacion_general WHERE id_usuario = ?";
|
||||
$stmtCheck = sqlsrv_query($conn, $sqlCheck, [$row['id_usuario']]);
|
||||
$checkRow = sqlsrv_fetch_array($stmtCheck, SQLSRV_FETCH_ASSOC);
|
||||
|
||||
if ($checkRow['total'] == 0) {
|
||||
$sqlInsert = "INSERT INTO informacion_general (id_usuario, nombre, rfc, telefono, correo)
|
||||
VALUES (?, ?, ?, ?, ?)";
|
||||
$paramsInsert = [$row['id_usuario'], $nombreUsuario, $rfc, $telefono, $email];
|
||||
sqlsrv_query($conn, $sqlInsert, $paramsInsert);
|
||||
} else {
|
||||
$sqlUpdate = "UPDATE informacion_general SET rfc = ?, telefono = ? WHERE id_usuario = ?";
|
||||
$paramsUpdate = [$rfc, $telefono, $row['id_usuario']];
|
||||
sqlsrv_query($conn, $sqlUpdate, $paramsUpdate);
|
||||
}
|
||||
|
||||
// Redirección por rol
|
||||
if ($row['tipo_usuario'] === 'importador') {
|
||||
header('Location: /IMPORTADORES/importadores/dashboard');
|
||||
|
||||
Reference in New Issue
Block a user