feat(login/register) blabla
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
$line = '2';
|
||||
include 'components/homepage/line.php';
|
||||
?>
|
||||
<hr>
|
||||
<?php
|
||||
$line = '5';
|
||||
$line = '8';
|
||||
include 'components/homepage/line.php';
|
||||
?>
|
||||
33
components/login/main.php
Normal file
33
components/login/main.php
Normal file
@@ -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,12 +19,12 @@
|
||||
<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>
|
||||
</table>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
50
components/register/main.php
Normal file
50
components/register/main.php
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user