Skip to main content
Sign in
Snippets Groups Projects
Commit a51d4a5d authored by Bitha17's avatar Bitha17
Browse files

add authentication

parent 422fe089
No related branches found
No related tags found
No related merge requests found
<?php <?php
// app/Controllers/EventController.php // app/Controllers/EventController.php
ob_start();
require_once(__DIR__ . '/../Models/Event.php'); require_once(__DIR__ . '/../Models/Event.php');
if (!isset($_SESSION["user_id"])) {
// User is not authenticated; redirect to login page
header("Location: /app/Views/login/login.php");
ob_end_flush();
}
class EventController { class EventController {
private $eventModel; private $eventModel;
... ...
......
<?php <?php
// app/controllers/ticketController.php // app/controllers/ticketController.php
ob_start();
// require_once 'Ticket.php'; // require_once 'Ticket.php';
require_once(__DIR__ . '/../Models/Ticket.php'); require_once(__DIR__ . '/../Models/Ticket.php');
if (!isset($_SESSION["user_id"])) {
// User is not authenticated; redirect to login page
header("Location: /app/Views/login/login.php");
ob_end_flush();
}
class TicketController { class TicketController {
private $ticketModel; private $ticketModel;
... ...
......
...@@ -38,6 +38,7 @@ class UserController { ...@@ -38,6 +38,7 @@ class UserController {
public function loginByEmail($email,$password) { public function loginByEmail($email,$password) {
$user = $this->userModel->getUserByEmail($email); $user = $this->userModel->getUserByEmail($email);
if ($user !== false && password_verify($password, $user['user_hashedPass'])) { if ($user !== false && password_verify($password, $user['user_hashedPass'])) {
session_start();
$_SESSION["user_id"] = $user['user_ID']; $_SESSION["user_id"] = $user['user_ID'];
return "success"; return "success";
} else { } else {
...@@ -48,6 +49,7 @@ class UserController { ...@@ -48,6 +49,7 @@ class UserController {
public function loginByUsername($username,$password) { public function loginByUsername($username,$password) {
$user = $this->userModel->getUserByUsername($username); $user = $this->userModel->getUserByUsername($username);
if ($user !== false && password_verify($password, $user['user_hashedPass'])) { if ($user !== false && password_verify($password, $user['user_hashedPass'])) {
session_start();
$_SESSION["user_id"] = $user['user_ID']; $_SESSION["user_id"] = $user['user_ID'];
return "success"; return "success";
} else { } else {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment