322 lines
13 KiB
PHP
322 lines
13 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Credenciales de administrador para la API
|
|
$api_username = 'admin@comunica.presidencia.gob.cu';
|
|
$api_password = '**4fgTK85pb';
|
|
$api_host = 'https://comunica.presidencia.gob.cu:5443/api/change_password';
|
|
|
|
// Configuración de la base de datos
|
|
$db_host = '172.16.0.51';
|
|
$db_name = 'db_pcu_manager';
|
|
$db_user = 'icomunica';
|
|
$db_pass = '**4fgTK85pbicomunica';
|
|
|
|
// Variables para mensajes
|
|
$success = '';
|
|
$error = '';
|
|
$showForm = true;
|
|
|
|
// Procesar formulario cuando se envía
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Recoger datos del formulario
|
|
$email = $_POST['email'] ?? '';
|
|
$current_password = $_POST['password'] ?? '';
|
|
$new_password = $_POST['new-password'] ?? '';
|
|
$confirm_password = $_POST['confirm-password'] ?? '';
|
|
$terms_accepted = isset($_POST['newsletter']);
|
|
|
|
// Validaciones básicas
|
|
if ($new_password !== $confirm_password) {
|
|
$error = "Las contraseñas nuevas no coinciden";
|
|
} else {
|
|
try {
|
|
// Conectar a la base de datos para verificar credenciales
|
|
$pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_user, $db_pass);
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
// Verificar usuario y contraseña actual
|
|
$stmt = $pdo->prepare("SELECT * FROM usuarios WHERE email = :email");
|
|
$stmt->execute(['email' => $email]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$user) {
|
|
$error = "Usuario no encontrado";
|
|
} elseif (!password_verify($current_password, $user['password'])) {
|
|
$error = "Contraseña actual incorrecta";
|
|
} else {
|
|
// Extraer usuario y dominio del email
|
|
$parts = explode('@', $email);
|
|
$user_api = $parts[0];
|
|
$domain = $parts[1];
|
|
|
|
// Llamar a la API para cambiar contraseña
|
|
$data = [
|
|
'user' => $user_api,
|
|
'host' => $domain,
|
|
'newpass' => $new_password
|
|
];
|
|
|
|
$ch = curl_init($api_host);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_POSTFIELDS => json_encode($data),
|
|
CURLOPT_USERPWD => "$api_username:$api_password",
|
|
CURLOPT_SSL_VERIFYHOST => false,
|
|
CURLOPT_SSL_VERIFYPEER => false
|
|
]);
|
|
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($http_code === 200 && $response === '0') {
|
|
// Actualizar contraseña en la base de datos local
|
|
$new_hash = password_hash($new_password, PASSWORD_DEFAULT);
|
|
$update_stmt = $pdo->prepare("UPDATE usuarios SET password = :password WHERE email = :email");
|
|
$update_stmt->execute([
|
|
'password' => $new_hash,
|
|
'email' => $email
|
|
]);
|
|
|
|
$success = "¡Contraseña actualizada exitosamente!";
|
|
$showForm = false;
|
|
} else {
|
|
$error = "Error en el servidor XMPP: " . htmlspecialchars($response);
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = "Error de base de datos: " . $e->getMessage();
|
|
} catch (Exception $e) {
|
|
$error = "Error general: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Cambiar Contraseña - IComunica</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
|
|
|
|
body {
|
|
font-family: 'Poppins', sans-serif;
|
|
background: linear-gradient(135deg, #f0f9ff 0%, #e6f7ff 100%);
|
|
}
|
|
|
|
.card {
|
|
box-shadow: 0 10px 30px -15px rgba(0, 0, 0, 0.1);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.card:hover {
|
|
box-shadow: 0 15px 40px -15px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.success-animation {
|
|
animation: successScale 0.5s ease-in-out;
|
|
}
|
|
|
|
@keyframes successScale {
|
|
0% {
|
|
transform: scale(0.9);
|
|
opacity: 0;
|
|
}
|
|
|
|
70% {
|
|
transform: scale(1.05);
|
|
opacity: 1;
|
|
}
|
|
|
|
100% {
|
|
transform: scale(1);
|
|
opacity: 1;
|
|
}
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
|
|
}
|
|
|
|
.password-toggle {
|
|
position: absolute;
|
|
right: 12px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
cursor: pointer;
|
|
color: #6b7280;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body class="min-h-screen flex items-center justify-center p-4">
|
|
<div class="w-full max-w-md">
|
|
<!-- Logo y título -->
|
|
<div class="text-center mb-8">
|
|
<div class="flex items-center justify-center mb-4">
|
|
<div class="bg-blue-600 text-white p-3 rounded-full">
|
|
<i class="fa-solid fa-comments text-2xl"></i>
|
|
</div>
|
|
<span class="ml-3 text-2xl font-bold text-gray-800">IComunica</span>
|
|
</div>
|
|
<h1 class="text-2xl font-bold text-gray-800">Cambiar Contraseña</h1>
|
|
</div>
|
|
|
|
<!-- Mensajes de éxito/error -->
|
|
<?php if ($success): ?>
|
|
<div class="success-animation bg-green-50 border border-green-200 rounded-lg p-6 mb-6 text-center">
|
|
<div class="text-green-600 mb-3">
|
|
<i class="fa-solid fa-circle-check text-4xl"></i>
|
|
</div>
|
|
<h3 class="text-lg font-medium text-green-800 mb-2">¡Operación Exitosa!</h3>
|
|
<p class="text-green-700"><?= $success ?></p>
|
|
<div class="mt-4">
|
|
<a href="#" class="text-blue-600 hover:underline" onclick="location.reload()">
|
|
<i class="fa-solid fa-rotate-right mr-1"></i> Volver al inicio
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
|
|
<div class="flex items-center">
|
|
<div class="text-red-600 mr-3">
|
|
<i class="fa-solid fa-circle-exclamation"></i>
|
|
</div>
|
|
<div>
|
|
<h3 class="text-sm font-medium text-red-800">Error</h3>
|
|
<p class="text-red-700 text-sm"><?= $error ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Formulario -->
|
|
<?php if ($showForm): ?>
|
|
<div class="card bg-white rounded-xl p-6 sm:p-8 shadow-lg">
|
|
<form method="POST">
|
|
<!-- Campo de usuario -->
|
|
<div class="mb-5">
|
|
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Usuario</label>
|
|
<div class="relative">
|
|
<input type="email" name="email" id="email" required
|
|
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"
|
|
placeholder="usuario@icomunica.presidencia.gob.cu">
|
|
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
|
|
<i class="fa-solid fa-user text-gray-400"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Contraseña actual -->
|
|
<div class="mb-5">
|
|
<label for="password" class="block text-sm font-medium text-gray-700 mb-1">Contraseña Actual</label>
|
|
<div class="relative">
|
|
<input type="password" name="password" id="password" required
|
|
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"
|
|
placeholder="••••••••">
|
|
<span class="password-toggle" onclick="togglePassword('password')">
|
|
<i class="fa-solid fa-eye text-gray-400"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Nueva contraseña -->
|
|
<div class="mb-5">
|
|
<label for="new-password" class="block text-sm font-medium text-gray-700 mb-1">Nueva Contraseña</label>
|
|
<div class="relative">
|
|
<input type="password" name="new-password" id="new-password" required
|
|
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"
|
|
placeholder="••••••••">
|
|
<span class="password-toggle" onclick="togglePassword('new-password')">
|
|
<i class="fa-solid fa-eye text-gray-400"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmar contraseña -->
|
|
<div class="mb-6">
|
|
<label for="confirm-password" class="block text-sm font-medium text-gray-700 mb-1">Confirmar Nueva Contraseña</label>
|
|
<div class="relative">
|
|
<input type="password" name="confirm-password" id="confirm-password" required
|
|
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition"
|
|
placeholder="••••••••">
|
|
<span class="password-toggle" onclick="togglePassword('confirm-password')">
|
|
<i class="fa-solid fa-eye text-gray-400"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Botón de envío -->
|
|
<button type="submit" class="btn-primary w-full text-white font-medium rounded-lg py-3 px-5 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
|
<i class="fa-solid fa-key mr-2"></i> Cambiar contraseña
|
|
</button>
|
|
</form>
|
|
|
|
<!-- Información de seguridad -->
|
|
<div class="mt-6 pt-6 border-t border-gray-200">
|
|
<div class="flex items-center text-sm text-gray-600">
|
|
<div class="mr-3 text-blue-600">
|
|
<i class="fa-solid fa-shield"></i>
|
|
</div>
|
|
<p>Tu seguridad es nuestra prioridad. Todas las comunicaciones están cifradas.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Footer -->
|
|
<div class="mt-8 text-center text-sm text-gray-500">
|
|
<p>© 2023 IComunica - Sistema de Mensajería Instantánea</p>
|
|
<p class="mt-1">Presidencia de la República de Cuba</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Función para mostrar/ocultar contraseña
|
|
function togglePassword(fieldId) {
|
|
const passwordField = document.getElementById(fieldId);
|
|
const icon = passwordField.nextElementSibling.querySelector('i');
|
|
|
|
if (passwordField.type === 'password') {
|
|
passwordField.type = 'text';
|
|
icon.classList.remove('fa-eye');
|
|
icon.classList.add('fa-eye-slash');
|
|
} else {
|
|
passwordField.type = 'password';
|
|
icon.classList.remove('fa-eye-slash');
|
|
icon.classList.add('fa-eye');
|
|
}
|
|
}
|
|
|
|
// Validar que las contraseñas coincidan
|
|
document.querySelector('form').addEventListener('submit', function(e) {
|
|
const newPassword = document.getElementById('new-password').value;
|
|
const confirmPassword = document.getElementById('confirm-password').value;
|
|
|
|
if (newPassword !== confirmPassword) {
|
|
e.preventDefault();
|
|
alert('Las contraseñas nuevas no coinciden. Por favor, verifique.');
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|