118 lines
3.3 KiB
PHP
118 lines
3.3 KiB
PHP
|
|
<?php
|
|
require_once 'db/config.php';
|
|
session_start();
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
if (empty($_POST['email']) || empty($_POST['password'])) {
|
|
$error = 'Por favor, preencha todos os campos.';
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
|
|
$stmt->execute([$_POST['email']]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($_POST['password'], $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['user_name'] = $user['name'];
|
|
$_SESSION['user_role'] = $user['role_id'];
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
$error = 'E-mail ou senha inválidos.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = 'Erro no banco de dados: ' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="pt-BR">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - Gestão Agrícola</title>
|
|
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
body {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
background-color: #f4f6f9;
|
|
}
|
|
.login-container {
|
|
background: #fff;
|
|
padding: 40px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
text-align: center;
|
|
}
|
|
.login-container h2 {
|
|
margin-bottom: 20px;
|
|
color: #2c3e50;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
text-align: left;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
}
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 4px;
|
|
}
|
|
.btn {
|
|
background-color: #27ae60;
|
|
color: #fff;
|
|
padding: 12px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
width: 100%;
|
|
font-size: 1rem;
|
|
}
|
|
.error {
|
|
color: #e74c3c;
|
|
margin-bottom: 15px;
|
|
}
|
|
.register-link {
|
|
margin-top: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<h2>Login</h2>
|
|
<?php if ($error): ?>
|
|
<p class="error"><?php echo $error; ?></p>
|
|
<?php endif; ?>
|
|
<form action="login.php" method="POST">
|
|
<div class="form-group">
|
|
<label for="email">E-mail</label>
|
|
<input type="email" id="email" name="email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Senha</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit" class="btn">Entrar</button>
|
|
</form>
|
|
<div class="register-link">
|
|
<p>Não tem uma conta? <a href="register.php">Cadastre-se</a></p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|