modulo de autenticacion
This commit is contained in:
+230
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
include("db.php");
|
||||
|
||||
$mensaje = "";
|
||||
$tipo_mensaje = "";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$nombre = trim($_POST['nombre']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
$confirm_password = $_POST['confirm_password'];
|
||||
|
||||
$acepto_politicas = isset($_POST['acepto_politicas']) ? true : false;
|
||||
$rol = "usuario";
|
||||
|
||||
// 1. Validamos políticas
|
||||
if (!$acepto_politicas) {
|
||||
$tipo_mensaje = "error";
|
||||
$mensaje = "Debes aceptar las políticas de privacidad para registrarte.";
|
||||
escribir_log("Registro fallido: Usuario no aceptó políticas (IP: " . $_SERVER['REMOTE_ADDR'] . ")");
|
||||
}
|
||||
// 2. Validamos contraseñas
|
||||
elseif ($password !== $confirm_password) {
|
||||
$tipo_mensaje = "error";
|
||||
$mensaje = "Las contraseñas no coinciden.";
|
||||
} else {
|
||||
// 3. Verificamos si el email ya existe
|
||||
$checkEmail = $conexion->prepare("SELECT id_usuario FROM usuarios WHERE email = ?");
|
||||
$checkEmail->bind_param("s", $email);
|
||||
$checkEmail->execute();
|
||||
$res = $checkEmail->get_result();
|
||||
|
||||
if ($res->num_rows > 0) {
|
||||
$tipo_mensaje = "error";
|
||||
$mensaje = "El email ya está registrado.";
|
||||
escribir_log("Intento de registro duplicado: El email $email ya existe.");
|
||||
} else {
|
||||
// 4. Encriptamos y guardamos
|
||||
$password_hash = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
||||
$stmt = $conexion->prepare("INSERT INTO usuarios (nombre, email, password, rol) VALUES (?, ?, ?, ?)");
|
||||
$stmt->bind_param("ssss", $nombre, $email, $password_hash, $rol);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$tipo_mensaje = "exito";
|
||||
$mensaje = "¡Registro exitoso! Ya podés iniciar sesión.";
|
||||
escribir_log("Nuevo usuario: $nombre ha creado una cuenta ($email).");
|
||||
} else {
|
||||
$tipo_mensaje = "error";
|
||||
$mensaje = "Error al registrar: " . $conexion->error;
|
||||
escribir_log("Error crítico de registro " . $conexion->error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Registro - La Pecosa</title>
|
||||
<link rel="stylesheet" href="css/all.min.css">
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-color: #fffef8;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.register-card {
|
||||
background: white;
|
||||
padding: 50px 40px;
|
||||
border-radius: 20px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.04);
|
||||
border: 1px solid rgba(224, 40, 40, 0.05);
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #333;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1.5px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
h2::after {
|
||||
content: '';
|
||||
display: block;
|
||||
width: 45px;
|
||||
height: 4px;
|
||||
background-color: #e02828;
|
||||
margin: 10px auto 0;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.msg {
|
||||
padding: 12px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.msg-error { background-color: #ffeaea; color: #e02828; }
|
||||
.msg-exito { background-color: #eaffea; color: #28a745; }
|
||||
|
||||
input {
|
||||
display: block;
|
||||
margin: 15px auto;
|
||||
padding: 15px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
font-size: 1rem;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
background-color: #ffffff;
|
||||
box-shadow: 0 0 0 2px rgba(224, 40, 40, 0.1);
|
||||
}
|
||||
|
||||
button {
|
||||
background: #e02828;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 15px;
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
border-radius: 50px;
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-top: 15px;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(224, 40, 40, 0.2);
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #c71f1f;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(224, 40, 40, 0.3);
|
||||
}
|
||||
|
||||
.login-link {
|
||||
display: block;
|
||||
margin-top: 25px;
|
||||
font-size: 14px;
|
||||
color: #777;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.login-link strong { color: #e02828; }
|
||||
.input-error { border: 2px solid #e02828 !important; }
|
||||
.input-success { border: 2px solid #28a745 !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="register-card">
|
||||
<h2>Crear Cuenta</h2>
|
||||
|
||||
<?php if ($mensaje != ""): ?>
|
||||
<div class="msg msg-<?php echo $tipo_mensaje; ?>">
|
||||
<?php echo $mensaje; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="registro.php" method="POST" id="registroForm">
|
||||
<input type="text" name="nombre" placeholder="Nombre completo" required>
|
||||
<input type="email" name="email" placeholder="Correo electrónico" required>
|
||||
|
||||
<input type="password" name="password" id="password" placeholder="Crear contraseña" required>
|
||||
<input type="password" name="confirm_password" id="confirm_password" placeholder="Confirmar contraseña" required>
|
||||
|
||||
<div style="text-align: left; margin: 20px 0; font-size: 13px; color: #666; display: flex; align-items: flex-start; gap: 10px;">
|
||||
<input type="checkbox" name="acepto_politicas" id="acepto_politicas" required
|
||||
style="width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: #e02828;">
|
||||
<label for="acepto_politicas" style="cursor: pointer; line-height: 1.4;">
|
||||
Acepto las <a href="privacidad.php" target="_blank" style="color: #e02828; text-decoration: none; font-weight: 700;">Políticas de Privacidad</a>
|
||||
y el uso de mi ubicación para envíos.
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit">Registrarme</button>
|
||||
</form>
|
||||
|
||||
<a href="login.php" class="login-link">
|
||||
¿Ya tenés cuenta? <strong>Iniciá sesión acá</strong>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const pass = document.getElementById('password');
|
||||
const confirmPass = document.getElementById('confirm_password');
|
||||
|
||||
function validarContraseñas() {
|
||||
if (confirmPass.value === "") {
|
||||
confirmPass.classList.remove('input-error', 'input-success');
|
||||
return;
|
||||
}
|
||||
|
||||
if (pass.value !== confirmPass.value) {
|
||||
confirmPass.classList.add('input-error');
|
||||
confirmPass.classList.remove('input-success');
|
||||
} else {
|
||||
confirmPass.classList.add('input-success');
|
||||
confirmPass.classList.remove('input-error');
|
||||
}
|
||||
}
|
||||
|
||||
confirmPass.addEventListener('input', validarContraseñas);
|
||||
pass.addEventListener('input', validarContraseñas);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user