v1
This commit is contained in:
commit
feeafa632b
6
dbconfig.php
Normal file
6
dbconfig.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
$host = '172.16.0.51';
|
||||
$db = 'db_pcu_manager';
|
||||
$user = 'icomunica';
|
||||
$password = '**4fgTK85pbicomunica';
|
||||
154
index.php
Normal file
154
index.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
//Credenciales de admin de 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 = '';
|
||||
|
||||
// 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 (!$terms_accepted) {
|
||||
$error = "Debe aceptar los términos y condiciones";
|
||||
} elseif ($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";
|
||||
} 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">
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
||||
<title>Cambiar Contrasenna</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body class="bg-gray-100 p-8">
|
||||
|
||||
<section class="bg-gray-50 dark:bg-gray-900">
|
||||
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
|
||||
<a href="#" class="flex items-center mb-6 text-2xl font-semibold text-gray-900 dark:text-white">
|
||||
<img class="w-8 h-8 mr-2" src="https://flowbite.s3.amazonaws.com/blocks/marketing-ui/logo.svg" alt="logo">
|
||||
IComunica
|
||||
</a>
|
||||
<div class="w-full p-6 bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md dark:bg-gray-800 dark:border-gray-700 sm:p-8">
|
||||
<h2 class="mb-1 text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
|
||||
Cambiar Contraseña
|
||||
</h2>
|
||||
<form class="mt-4 space-y-4 lg:mt-5 md:space-y-5" action="#">
|
||||
<div>
|
||||
<label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Tu usuario</label>
|
||||
<input type="email" name="email" id="email" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="name@icomunica.presidencia.gob.cu" required="">
|
||||
</div>
|
||||
<div>
|
||||
<label for="password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Contraseña</label>
|
||||
<input type="password" name="password" id="password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
|
||||
</div>
|
||||
<div>
|
||||
<label for="new-password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Nueva contraseña</label>
|
||||
<input type="new-password" name="new-password" id="new-password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
|
||||
</div>
|
||||
<div>
|
||||
<label for="confirm-password" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Confirma la contraseña</label>
|
||||
<input type="confirm-password" name="confirm-password" id="confirm-password" placeholder="••••••••" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required="">
|
||||
</div>
|
||||
<div class="flex items-start">
|
||||
<div class="flex items-center h-5">
|
||||
<input id="newsletter" aria-describedby="newsletter" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800" required="">
|
||||
</div>
|
||||
<div class="ml-3 text-sm">
|
||||
<label for="newsletter" class="font-light text-gray-500 dark:text-gray-300">I acepto los <a class="font-medium text-primary-600 hover:underline dark:text-primary-500" href="#">Terminos y condicionesw</a></label>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">Cambiar contraseña</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user