From 117b6a9217caf6c20ec1ce905850bba4df069167 Mon Sep 17 00:00:00 2001 From: p1907961 Date: Fri, 18 Dec 2020 20:29:24 +0100 Subject: [PATCH] Init commit --- .gitignore | 1 + .htaccess | 5 +++ assets/css/main.css | 58 +++++++++++++++++++++++++++++ config/config.php | 28 ++++++++++++++ controller/404.php | 2 + controller/accomodation.php | 20 ++++++++++ controller/index.php | 8 ++++ controller/login.php | 27 ++++++++++++++ controller/logout.php | 4 ++ index.php | 40 ++++++++++++++++++++ models/Accomodation.php | 11 ++++++ models/AccomodationServices.php | 11 ++++++ models/User.php | 52 ++++++++++++++++++++++++++ src/func.php | 25 +++++++++++++ src/lang/en.json | 1 + src/lang/fr.json | 5 +++ src/model.php | 65 +++++++++++++++++++++++++++++++++ view/add_accomodation.php | 60 ++++++++++++++++++++++++++++++ view/edit_accomodation.php | 7 ++++ view/index.php | 8 ++++ view/login.php | 17 +++++++++ view/template/footer.php | 5 +++ view/template/head.php | 16 ++++++++ view/template/navbar.php | 32 ++++++++++++++++ 24 files changed, 508 insertions(+) create mode 100644 .gitignore create mode 100644 .htaccess create mode 100644 assets/css/main.css create mode 100644 config/config.php create mode 100644 controller/404.php create mode 100644 controller/accomodation.php create mode 100644 controller/index.php create mode 100644 controller/login.php create mode 100644 controller/logout.php create mode 100644 index.php create mode 100644 models/Accomodation.php create mode 100644 models/AccomodationServices.php create mode 100644 models/User.php create mode 100644 src/func.php create mode 100644 src/lang/en.json create mode 100644 src/lang/fr.json create mode 100644 src/model.php create mode 100644 view/add_accomodation.php create mode 100644 view/edit_accomodation.php create mode 100644 view/index.php create mode 100644 view/login.php create mode 100644 view/template/footer.php create mode 100644 view/template/head.php create mode 100644 view/template/navbar.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..9afb29f --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_URI} !^(/AccomodationCPOA/assets) +RewriteRule ^.*$ /AccomodationCPOA/index.php [L,QSA] \ No newline at end of file diff --git a/assets/css/main.css b/assets/css/main.css new file mode 100644 index 0000000..7c310a5 --- /dev/null +++ b/assets/css/main.css @@ -0,0 +1,58 @@ +/* +Layout + */ +html, +body { + height: 100%; +} + +.section { + padding-top: 80px; +} + +/* + Login + */ +.login { + 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; +} + +.login .form-signin { + width: 100%; + max-width: 330px; + padding: 15px; + margin: 0 auto; +} +.login .form-signin .checkbox { + font-weight: 400; +} +.login .form-signin .form-control { + position: relative; + box-sizing: border-box; + height: auto; + padding: 10px; + font-size: 16px; +} +.login .form-signin .form-control:focus { + z-index: 2; +} +.login .form-signin input[type="email"] { + margin-bottom: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} +.login .form-signin input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..301c37a --- /dev/null +++ b/config/config.php @@ -0,0 +1,28 @@ +isLoggedIn()) { + if(isset($path[1])) { + switch ($path[1]) { + case 'add': + $services = (new AccomodationServices())->getAll(); + require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + break; + case 'edit': + require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php'); + break; + default: + redirect(); + } + }else{ + redirect(); + } +}else{ + redirect('login'); +} \ No newline at end of file diff --git a/controller/index.php b/controller/index.php new file mode 100644 index 0000000..50200f2 --- /dev/null +++ b/controller/index.php @@ -0,0 +1,8 @@ +isLoggedIn()) { + if (!isset($path[1])) { + require_once(VIEW_PATH . $path[0] . '.php'); + } +}else{ + redirect('login'); +} \ No newline at end of file diff --git a/controller/login.php b/controller/login.php new file mode 100644 index 0000000..2d9fbe2 --- /dev/null +++ b/controller/login.php @@ -0,0 +1,27 @@ +isLoggedIn() && !isset($path[1])) { + if(isset($_POST['email'],$_POST['password'])){ + $user = new User; + $userArray = $user->fetch( + array( + ['email','=',$_POST['email']], + ['passwordHash', '=', hash('sha256',$_POST['password'])] + ) + ); + if(count($userArray) === 1){ + /* + * Successful login + */ + $_SESSION['user'] = $userArray[0]; // Pass the returned User type data into Session + redirect(); + }else{ + /* + * Error message + */ + } + } + require_once(VIEW_PATH . $path[0] . '.php'); +}else{ + redirect(); +} \ No newline at end of file diff --git a/controller/logout.php b/controller/logout.php new file mode 100644 index 0000000..13c9b2f --- /dev/null +++ b/controller/logout.php @@ -0,0 +1,4 @@ +prepare('SELECT * FROM Accomodation WHERE UserEmail = ?'); + $q->execute(array($email)); + return $q->fetch(PDO::FETCH_ASSOC); + } +} \ No newline at end of file diff --git a/models/AccomodationServices.php b/models/AccomodationServices.php new file mode 100644 index 0000000..3f68a4b --- /dev/null +++ b/models/AccomodationServices.php @@ -0,0 +1,11 @@ +prepare('SELECT * FROM AccomodationServices'); + $q->execute(); + return $q->fetchAll(PDO::FETCH_ASSOC); + } +} \ No newline at end of file diff --git a/models/User.php b/models/User.php new file mode 100644 index 0000000..43cf14f --- /dev/null +++ b/models/User.php @@ -0,0 +1,52 @@ +$value){ + if(!key_exists($key, $_col)){ + throw new Exception('Invalid data entry'); + }else{ + $this->data[$key] = $value; + } + } + } + return $this; + } + /* + * Getters + */ + public function getEmail(){ + if(isset($this->data['email'])) + return $this->data['email']; + return false; + } + public function getFirstName(){ + if(isset($this->data['firstName'])) + return $this->data['firstName']; + return false; + } + public function getLastName(){ + if(isset($this->data['lastName'])) + return $this->data['lastName']; + return false; + } + public function getPhoneNumber(){ + if(isset($this->data['phoneNumber'])) + return $this->data['phoneNumber']; + return false; + } + + public function isLoggedIn(){ + return (isset($this->data['email'])); + } + + +} \ No newline at end of file diff --git a/src/func.php b/src/func.php new file mode 100644 index 0000000..1e57a43 --- /dev/null +++ b/src/func.php @@ -0,0 +1,25 @@ +' .htmlspecialchars($name). ''; +} diff --git a/src/lang/en.json b/src/lang/en.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/src/lang/en.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/lang/fr.json b/src/lang/fr.json new file mode 100644 index 0000000..3b12403 --- /dev/null +++ b/src/lang/fr.json @@ -0,0 +1,5 @@ +{ + "layout": { + + } +} \ No newline at end of file diff --git a/src/model.php b/src/model.php new file mode 100644 index 0000000..7316964 --- /dev/null +++ b/src/model.php @@ -0,0 +1,65 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch(Exception $e){ + var_dump($e); + } + } + /* + * GET/SELECT Query + */ + public static function fetch($filters = []){ + $query = 'SELECT * FROM ' . get_called_class(); + $args = []; + $c = 0; + $output = []; + $_col = get_called_class()::getColumns(); + forEach($filters as $filter){ + if (count($filter) === 3 && array_key_exists($filter[0], $_col) && in_array($filter[1], ['=','<','>','<>','LIKE'])){ + if($c === 0){ + $query .= ' WHERE'; + }else{ + $query .= ' AND'; + } + $query .= ' ' . $filter[0] . ' ' . $filter[1] . ' ?'; + $args[] = $filter[2]; + }else{ + throw new Exception('Invalid SQL filters'); + } + $c++; + } + $q = Model::$db->prepare($query); + $q->execute($args); + $d = $q->fetchAll(PDO::FETCH_ASSOC); + forEach($d as $row){ + $class=get_called_class(); + $output[] = new $class($row); + } + return $output; + } + protected function getColumns(){ + $q = Model::$db->prepare('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?'); + $q->execute(array(get_called_class())); + $d = $q->fetchAll(PDO::FETCH_ASSOC); + $out = []; + forEach($d as $col){ + $out[$col['COLUMN_NAME']] = $col; + } + return $out; + } +} +/* + * Load our models + */ +foreach (glob(MODELS_PATH . '/*.php') as $filename) +{ + require_once $filename; +} \ No newline at end of file diff --git a/view/add_accomodation.php b/view/add_accomodation.php new file mode 100644 index 0000000..2170524 --- /dev/null +++ b/view/add_accomodation.php @@ -0,0 +1,60 @@ + +
+

Bienvenue M. getLastName()))?>,

+

Il semblerait que vous n'ayez pas encore ajouté d'hebergement...

+
+
+
+
+
+
+ + + We'll never share your email with anyone else. +
+
+ + +
+
+ + +
+
+
+
+
+ + +
+
+
+ +
+ + +
+ +
+ +
+
+
+
+ \ No newline at end of file diff --git a/view/edit_accomodation.php b/view/edit_accomodation.php new file mode 100644 index 0000000..bc0e1a5 --- /dev/null +++ b/view/edit_accomodation.php @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/view/index.php b/view/index.php new file mode 100644 index 0000000..ea5b40f --- /dev/null +++ b/view/index.php @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/view/login.php b/view/login.php new file mode 100644 index 0000000..77e3126 --- /dev/null +++ b/view/login.php @@ -0,0 +1,17 @@ + +
+ +
+ \ No newline at end of file diff --git a/view/template/footer.php b/view/template/footer.php new file mode 100644 index 0000000..771f847 --- /dev/null +++ b/view/template/footer.php @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/view/template/head.php b/view/template/head.php new file mode 100644 index 0000000..8a16068 --- /dev/null +++ b/view/template/head.php @@ -0,0 +1,16 @@ + + + + + + + "> + + - <?= WEBSITE_NAME ?> + + + \ No newline at end of file diff --git a/view/template/navbar.php b/view/template/navbar.php new file mode 100644 index 0000000..596f76f --- /dev/null +++ b/view/template/navbar.php @@ -0,0 +1,32 @@ + \ No newline at end of file