mirror of https://github.com/itsmrval/subway
feat(login/register) blabla
parent
f6570e074c
commit
10825d7598
|
|
@ -0,0 +1,49 @@
|
|||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
display: -ms-flexbox;
|
||||
display: -webkit-box;
|
||||
display: flex;
|
||||
-ms-flex-align: center;
|
||||
-ms-flex-pack: center;
|
||||
-webkit-box-align: center;
|
||||
align-items: center;
|
||||
-webkit-box-pack: center;
|
||||
justify-content: center;
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.form-signin {
|
||||
width: 100%;
|
||||
max-width: 330px;
|
||||
padding: 15px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.form-signin .checkbox {
|
||||
font-weight: 400;
|
||||
}
|
||||
.form-signin .form-control {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
height: auto;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
.form-signin .form-control:focus {
|
||||
z-index: 2;
|
||||
}
|
||||
.form-signin input[type="email"] {
|
||||
margin-bottom: -1px;
|
||||
border-bottom-right-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
.form-signin input[type="password"] {
|
||||
margin-bottom: 10px;
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
$line = '2';
|
||||
include 'components/homepage/line.php';
|
||||
?>
|
||||
<hr>
|
||||
<?php
|
||||
$line = '5';
|
||||
$line = '8';
|
||||
include 'components/homepage/line.php';
|
||||
?>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
$query = $conn->prepare("SELECT * FROM users WHERE email = :email");
|
||||
$query->bindParam(':email', $_POST['email']);
|
||||
$query->execute();
|
||||
$user = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['first_name'] = $user['first_name'];
|
||||
$_SESSION['is_admin'] = $user['is_admin'];
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
$errorMessage = "Invalid email or password.";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<body class="text-center">
|
||||
<form class="form-signin" method="POST" action="login.php">
|
||||
<img class="mb-4" src="assets/logo/dark.png" alt="" width="256px">
|
||||
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
|
||||
<?= isset($errorMessage) ? '<div class="alert alert-danger" role="alert">' . $errorMessage . '</div>' : '' ?>
|
||||
<input type="email" id="email" name="email" class="form-control mt-2" placeholder="damien.dupuis@gmail.com" required autofocus>
|
||||
<input type="password" id="password" name="password" class="form-control mt-2" placeholder="Password" required>
|
||||
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Continue</button>
|
||||
<p class="mt-5 mb-3 text-muted">Not registered ? <a class="text-decoration-none" href="/register.php">Create an account here</a></p>
|
||||
</form>
|
||||
</body>
|
||||
|
|
@ -1,5 +1,14 @@
|
|||
<?php
|
||||
include 'services/stop_service.php';
|
||||
|
||||
function getStops($line) {
|
||||
$json = file_get_contents(__DIR__ . '/../../data/stops.json');
|
||||
$data = json_decode($json, true);
|
||||
$result = array_filter($data, function($item) use ($line) {
|
||||
return $item['fields']['mode'] === 'METRO' && $item['fields']['indice_lig'] === "$line";
|
||||
});
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Lignes de Métro</h2>
|
||||
|
|
@ -20,7 +29,6 @@ include 'services/stop_service.php';
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<?php
|
||||
$stops = getStops($i);
|
||||
include 'components/navigate/stop_list.php';
|
||||
?>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<div class="row">
|
||||
<?php
|
||||
$stations = array_fill(1, 10, 'Station');
|
||||
|
||||
$stations = getStops($i);
|
||||
|
||||
$half = ceil(count($stations) / 2);
|
||||
$chunks = array_chunk($stations, ceil(count($stations) / 2), true);
|
||||
?>
|
||||
|
|
@ -17,8 +19,8 @@
|
|||
<tbody>
|
||||
<?php foreach ($chunk as $station): ?>
|
||||
<tr>
|
||||
<td><?php echo $station; ?></td>
|
||||
<td class="text-end"><div class="btn btn-success">Ajouter</div></td>
|
||||
<td><?php echo htmlspecialchars($station['fields']['nom_zda']); ?></td>
|
||||
<td class="text-end"><button class="btn btn-success">Ajouter</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
if ($_POST['password'] !== $_POST['confirmPassword']) {
|
||||
$errorMessage = "Password doesnt match";
|
||||
} else {
|
||||
$query = $conn->prepare("SELECT * FROM users WHERE email = :email");
|
||||
$query->bindParam(':email', $_POST['email']);
|
||||
$query->execute();
|
||||
$user = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user) {
|
||||
$errorMessage = "Email already used.";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<body class="text-center">
|
||||
<form class="form-signin" method="POST" action="register.php">
|
||||
<img src="assets/logo/dark.png" alt="" width="256px">
|
||||
<h1 class="h3 mb-3 font-weight-normal">Create an account</h1>
|
||||
<?= isset($errorMessage) ? '<div class="alert alert-danger" role="alert">' . $errorMessage . '</div>' : '' ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input type="text" id="firstName" name="firstName" class="form-control mt-2" placeholder="Damien" required>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input type="text" id="lastName" name="lastName" class="form-control mt-2" placeholder="Dupuis" required>
|
||||
</div>
|
||||
</div>
|
||||
<input type="email" id="email" name="email" class="form-control mt-2" placeholder="damien.dupuis@gmail.com" required>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input type="password" id="password" name="password" class="form-control" placeholder="Password" required>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input type="password" id="confirmPassword" name="confirmPassword" class="form-control" placeholder="Confirmation" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-lg btn-primary btn-block mt-4" type="submit">Continue</button>
|
||||
<p class="mt-5 mb-3 text-muted">Already an account ? <a class="text-decoration-none" href="/login.php">Login here</a></p>
|
||||
</form>
|
||||
</body>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
$content = 'components/homepage/main.php';
|
||||
include 'structure/main.php';
|
||||
?>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
$content = 'components/login/main.php';
|
||||
include 'structure/main.php';
|
||||
?>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
?>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
$content = 'components/register/main.php';
|
||||
include 'structure/main.php';
|
||||
?>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
try {
|
||||
$conn = new PDO("mysql:host=127.0.0.1", "root", "lynqo");
|
||||
$conn->exec("CREATE DATABASE IF NOT EXISTS subwaySchedule");
|
||||
$conn->exec("USE subwaySchedule");
|
||||
|
||||
$conn->exec("CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
firstName VARCHAR(50) NOT NULL,
|
||||
lastName VARCHAR(50) NOT NULL,
|
||||
email VARCHAR(100) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
is_admin BOOLEAN NOT NULL DEFAULT 0
|
||||
)");
|
||||
|
||||
|
||||
|
||||
} catch(PDOException $e) {
|
||||
echo "Connection failed: " . $e->getMessage();
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
function getStops($line) {
|
||||
$json = file_get_contents("../data/stops.json");
|
||||
$data = json_decode($json, true);
|
||||
$result = array_filter($data, function($item) use ($line) {
|
||||
return $item['fields']['mode'] === 'METRO' && $item['fields']['indice_lig'] === "$line";
|
||||
});
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
@ -5,6 +5,10 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Subway schedules</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
|
||||
<?php
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
echo '<link href="assets/css/login.css" rel="stylesheet">';
|
||||
}
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -1,5 +1,20 @@
|
|||
<?php include 'structure/header.php'; ?>
|
||||
<?php include 'structure/navbar.php'; ?>
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$page = basename($_SERVER['PHP_SELF']);
|
||||
if (!isset($_SESSION['user_id']) && $page !== 'login.php' && $page !== 'register.php') {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
} else if (isset($_SESSION['user_id']) && ($page === 'login.php' || $page === 'register.php')) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
include 'structure/header.php';
|
||||
include 'structure/navbar.php';
|
||||
include 'services/db.php';
|
||||
|
||||
?>
|
||||
|
||||
<main class="container mt-5">
|
||||
<?php include $content; ?>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
<?php
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
echo '
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Subways</a>
|
||||
<a class="navbar-brand" href="/">Subways</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
|
@ -16,10 +20,16 @@
|
|||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Mon compte</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/logout.php">Déconnexion</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="ms-auto">
|
||||
<a class="btn btn-primary" href="#">Gestion des utilisateurs</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
</header>';
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue