Skip to content

Commit

Permalink
Merge pull request #27 from wanderlust-group-project-1/nirmal
Browse files Browse the repository at this point in the history
docker environment
  • Loading branch information
nsavinda authored Oct 27, 2023
2 parents fdd2dbb + b008cd5 commit 83ded72
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/controllers/Admin/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

echo "This is the index page";



?>
12 changes: 12 additions & 0 deletions app/controllers/Admin/Home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

class Home {
use Controller;

public function index(string $a = '', string $b = '', string $c = ''):void {
$this->view('admin/home');
}
}


?>
55 changes: 55 additions & 0 deletions app/controllers/Admin/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Firebase\JWT\JWT;


class Login {
use Controller;

private function setcookie(array $userData): void{
print_r($userData);
$token = JWT::encode($userData, SECRET_KEY, 'HS256');

setcookie('jwt_auth_token', $token, time() + 36000, '/', '', false, true);

// echo json_encode(['token' => $token]);

}
private function post(): mixed {
$user = new UserModel;
$email = $_POST['email'];
$password = $_POST['password'];

if ($user->authenticate($email, $password)) {
$userData = $user->authenticate($email, $password);
// $_SESSION['USER'] = $userData;
// filter user data get id and email array
$userData = array_filter((array) $userData, function ($key) {
return in_array($key, ['id', 'email']);
}, ARRAY_FILTER_USE_KEY);
$this->setcookie($userData);
redirect('home');
} else {
$data['errors'] = ['email' => 'Wrong Email or Password'];
return $data;

}

}


public function index(): void {


if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = $this->post();
}else {
$data = [];
}


$this->view('admin/login', $data);
}
}

?>
39 changes: 33 additions & 6 deletions app/core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,43 @@ public function loadController(): void {
$URL = $this->splitURL();

// Select controller
$filename = "../app/controllers/" . ucfirst($URL[0]) . ".php";
if (file_exists($filename)) {
require $filename;
$this->controller = ucfirst($URL[0]);
if ($URL[0] == 'admin'){
unset($URL[0]);
// echo $URL[1];

$filename = "../app/controllers/Admin/" . ucfirst($URL[1]) . ".php";

if (file_exists($filename)) {
require $filename;
$this->controller = ucfirst($URL[1]);
// echo $this->controller;
unset($URL[1]);
} else {
require "../app/controllers/_404.php";
$this->controller = "_404";
}
} else {
require "../app/controllers/_404.php";
$this->controller = "_404";
$filename = "../app/controllers/" . ucfirst($URL[0]) . ".php";
if (file_exists($filename)) {
require $filename;
$this->controller = ucfirst($URL[0]);
unset($URL[0]);
} else {
require "../app/controllers/_404.php";
$this->controller = "_404";
}
}

// $filename = "../app/controllers/" . ucfirst($URL[0]) . ".php";
// if (file_exists($filename)) {
// require $filename;
// $this->controller = ucfirst($URL[0]);
// unset($URL[0]);
// } else {
// require "../app/controllers/_404.php";
// $this->controller = "_404";
// }

// Run middleware before executing the controller's action

$controller = new $this->controller;
Expand Down
15 changes: 15 additions & 0 deletions app/views/admin/components/navbar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<nav class="sidebar">
<div class="logo">
<img src="<?= ROOT_DIR ?>/assets/images/logo.png" alt="logo">
</div>
<ul class="nav-menu">
<li class="nav-menu-item"><a href="#">Home</a></li>
<li class="nav-menu-item"><a href="#">About</a></li>
<li class="nav-menu-item"><a href="#">Guides</a></li>
<li class="nav-menu-item"><a href="#">Rental Services</a></li>
<li class="nav-menu-item"><a href="#">Blogs</a></li>
<li class="nav-menu-item"><a href="#">Tips & Knowhows</a></li>
<li class="nav-menu-item"><a href="#">Complaints</a></li>
</ul>
<div class="login-button"><a href="#">Login</a></div>
</nav>
Empty file added app/views/admin/home.view.php
Empty file.
3 changes: 3 additions & 0 deletions app/views/admin/layout/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

</body>
</html>
8 changes: 8 additions & 0 deletions app/views/admin/layout/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

<html>
<head>
<title>Wanderlust</title>
<link rel="stylesheet" type="text/css" href="<?=ROOT_DIR ?>/assets/css/style.css">
</head>
<body>

48 changes: 48 additions & 0 deletions app/views/admin/login.view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
require_once('../app/views/admin/layout/header.php');
// require_once('../app/views/components/navbar.php');


?>
<div class="login-container">
<!-- <h1>Login</h1> -->
<div class="login-form">
<form id="loginForm" action="<?=ROOT_DIR?>/login" method="post">
<h2>Login</h2>


<?php if(isset($errors)): ?>
<div> <?= implode('<br>', $errors)?> </div>
<?php endif; ?>

<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="Email" required>
<label for="password" >Password</label>
<input type="password" name="password" id="password" placeholder="Password" required>
<div class="message-text">
<a href="#">Forgot your password?</a>
</div>
<input type="submit" name="submit" value="login">

<p>
Don't have an account? <a href="<?=ROOT_DIR?>/signup">Signup</a>
<p>


</form>
<!-- <a href="<?=ROOT_DIR?>/signup" title="Signup">Signup</a>
<a href="<?=ROOT_DIR?>" title="Home">Home</a> -->
</div>
</div>


<script src="<?=ROOT_DIR?>/assets/js/login.js"></script>

<?php
require_once('../app/views/admin/layout/footer.php');


?>



5 changes: 5 additions & 0 deletions database/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_USER=root
DB_PASSWORD=root
DB_HOST=localhost
DB_NAME=wanderlust
DUMP_FILE_NAME=wanderlust
5 changes: 5 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: '1.0'
services:
web-server:
hostname: wanderlust
container_name: wl-server
build:
dockerfile: php.Dockerfile
context: .
Expand All @@ -13,6 +15,8 @@ services:
ports:
- 8000:80
mysql-server:
hostname: wl-mysql
container_name: wl-mysql
image: mysql:8.1
restart: always
# ports:
Expand All @@ -25,6 +29,7 @@ services:
- ./database:/docker-entrypoint-initdb.d

phpmyadmin:

image: phpmyadmin/phpmyadmin
restart: always
ports:
Expand Down
5 changes: 5 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_USER=root
DB_PASSWORD=root
DB_HOST=wl-mysql
DB_NAME=wanderlust
DUMP_FILE_NAME=wanderlust
1 change: 1 addition & 0 deletions php.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY composer.json composer.lock /var/www/
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN composer install --working-dir=/var/www

COPY .env /var/www

# allow .htaccess with RewriteEngine
RUN a2enmod rewrite
Expand Down

0 comments on commit 83ded72

Please sign in to comment.