From a4a437d1ff197ad79a22cdfa24b0fe3a18461b28 Mon Sep 17 00:00:00 2001 From: trungpv Date: Sat, 1 Sep 2018 10:57:15 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=89=20Change=20something=20make=20this?= =?UTF-8?q?=20great=20again=20=F0=9F=9A=80=20=F0=9F=98=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .htaccess | 26 + README.MD | 49 ++ composer.json | 22 +- composer.lock | 808 +++++++++++++++--- core/app/Controllers/AuthController.php | 110 +++ core/app/Controllers/Controller.php | 14 + .../app}/Controllers/ErrorController.php | 5 +- .../app}/Controllers/IndexController.php | 38 +- core/app/Controllers/UserController.php | 207 +++++ core/app/Controllers/WebsiteController.php | 194 +++++ core/app/Models/User.php | 11 + core/app/Models/Website.php | 16 + core/app/Validation/UniqueRule.php | 41 + {bootstrap => core/bootstrap}/app.php | 80 +- core/helpers.php | 89 ++ core/routes.php | 27 + {views => core/views}/errors/404.php | 0 {views => core/views}/errors/405.php | 0 {views => core/views}/errors/500.php | 0 core/views/index.php | 83 ++ {views => core/views}/layouts/app.php | 6 + {views => core/views}/layouts/auth.php | 0 {views => core/views}/layouts/footer.php | 0 {views => core/views}/layouts/navigation.php | 24 +- {views => core/views}/layouts/topnavbar.php | 11 +- core/views/login.php | 54 ++ {views => core/views}/register.php | 0 core/views/users/index.php | 128 +++ core/views/users/store.php | 74 ++ core/views/users/update.php | 91 ++ core/views/websites/index.php | 115 +++ core/views/websites/store.php | 63 ++ core/views/websites/update.php | 64 ++ {public/css => css}/AdminLTE.css | 0 {public/css => css}/AdminLTE.min.css | 0 .../alt/AdminLTE-bootstrap-social.css | 0 .../alt/AdminLTE-bootstrap-social.min.css | 0 .../css => css}/alt/AdminLTE-fullcalendar.css | 0 .../alt/AdminLTE-fullcalendar.min.css | 0 {public/css => css}/alt/AdminLTE-select2.css | 0 .../css => css}/alt/AdminLTE-select2.min.css | 0 .../alt/AdminLTE-without-plugins.css | 0 .../alt/AdminLTE-without-plugins.min.css | 0 {public/css => css}/skins/_all-skins.css | 0 {public/css => css}/skins/_all-skins.min.css | 0 .../css => css}/skins/skin-black-light.css | 0 .../skins/skin-black-light.min.css | 0 {public/css => css}/skins/skin-black.css | 0 {public/css => css}/skins/skin-black.min.css | 0 {public/css => css}/skins/skin-blue-light.css | 0 .../css => css}/skins/skin-blue-light.min.css | 0 {public/css => css}/skins/skin-blue.css | 0 {public/css => css}/skins/skin-blue.min.css | 0 .../css => css}/skins/skin-green-light.css | 0 .../skins/skin-green-light.min.css | 0 {public/css => css}/skins/skin-green.css | 0 {public/css => css}/skins/skin-green.min.css | 0 .../css => css}/skins/skin-purple-light.css | 0 .../skins/skin-purple-light.min.css | 0 {public/css => css}/skins/skin-purple.css | 0 {public/css => css}/skins/skin-purple.min.css | 0 {public/css => css}/skins/skin-red-light.css | 0 .../css => css}/skins/skin-red-light.min.css | 0 {public/css => css}/skins/skin-red.css | 0 {public/css => css}/skins/skin-red.min.css | 0 .../css => css}/skins/skin-yellow-light.css | 0 .../skins/skin-yellow-light.min.css | 0 {public/css => css}/skins/skin-yellow.css | 0 {public/css => css}/skins/skin-yellow.min.css | 0 database.sql | 34 + helpers.php | 6 - {public/img => img}/avatar.png | Bin {public/img => img}/avatar04.png | Bin {public/img => img}/avatar2.png | Bin {public/img => img}/avatar3.png | Bin {public/img => img}/avatar5.png | Bin {public/img => img}/boxed-bg.jpg | Bin {public/img => img}/boxed-bg.png | Bin .../img => img}/credit/american-express.png | Bin {public/img => img}/credit/cirrus.png | Bin {public/img => img}/credit/mastercard.png | Bin {public/img => img}/credit/mestro.png | Bin {public/img => img}/credit/paypal.png | Bin {public/img => img}/credit/paypal2.png | Bin {public/img => img}/credit/visa.png | Bin {public/img => img}/default-50x50.gif | Bin {public/img => img}/icons.png | Bin {public/img => img}/photo1.png | Bin {public/img => img}/photo2.png | Bin {public/img => img}/photo3.jpg | Bin {public/img => img}/photo4.jpg | Bin {public/img => img}/user1-128x128.jpg | Bin {public/img => img}/user2-160x160.jpg | Bin {public/img => img}/user3-128x128.jpg | Bin {public/img => img}/user4-128x128.jpg | Bin {public/img => img}/user5-128x128.jpg | Bin {public/img => img}/user6-128x128.jpg | Bin {public/img => img}/user7-128x128.jpg | Bin {public/img => img}/user8-128x128.jpg | Bin index.php | 6 + {public/js => js}/adminlte.js | 0 {public/js => js}/adminlte.min.js | 0 {public/js => js}/app.js | 0 {public/js => js}/app.min.js | 0 {public/js => js}/demo.js | 0 {public/js => js}/pages/dashboard.js | 0 {public/js => js}/pages/dashboard2.js | 0 .../Ionicons/css/ionicons.css | 0 .../Ionicons/css/ionicons.min.css | 0 .../Ionicons/fonts/ionicons.eot | Bin .../Ionicons/fonts/ionicons.svg | 0 .../Ionicons/fonts/ionicons.ttf | Bin .../Ionicons/fonts/ionicons.woff | Bin .../bootstrap/css/bootstrap-theme.css | 0 .../bootstrap/css/bootstrap-theme.css.map | 0 .../bootstrap/css/bootstrap-theme.min.css | 0 .../bootstrap/css/bootstrap-theme.min.css.map | 0 .../bootstrap/css/bootstrap.css | 0 .../bootstrap/css/bootstrap.css.map | 0 .../bootstrap/css/bootstrap.min.css | 0 .../bootstrap/css/bootstrap.min.css.map | 0 .../fonts/glyphicons-halflings-regular.eot | Bin .../fonts/glyphicons-halflings-regular.svg | 0 .../fonts/glyphicons-halflings-regular.ttf | Bin .../fonts/glyphicons-halflings-regular.woff | Bin .../fonts/glyphicons-halflings-regular.woff2 | Bin .../bootstrap/js/bootstrap.js | 0 .../bootstrap/js/bootstrap.min.js | 0 .../plugins => plugins}/bootstrap/js/npm.js | 0 plugins/clipboard.js/clipboard.min.js | 7 + .../fastclick/fastclick.js | 0 .../font-awesome/css/font-awesome.css | 0 .../font-awesome/css/font-awesome.css.map | 0 .../font-awesome/css/font-awesome.min.css | 0 .../font-awesome/fonts/FontAwesome.otf | Bin .../fonts/fontawesome-webfont.eot | Bin .../fonts/fontawesome-webfont.svg | 0 .../fonts/fontawesome-webfont.ttf | Bin .../fonts/fontawesome-webfont.woff | Bin .../fonts/fontawesome-webfont.woff2 | Bin {public/plugins => plugins}/iCheck/all.css | 0 .../plugins => plugins}/iCheck/flat/_all.css | 0 .../plugins => plugins}/iCheck/flat/aero.css | 0 .../plugins => plugins}/iCheck/flat/aero.png | Bin .../iCheck/flat/aero@2x.png | Bin .../plugins => plugins}/iCheck/flat/blue.css | 0 .../plugins => plugins}/iCheck/flat/blue.png | Bin .../iCheck/flat/blue@2x.png | Bin .../plugins => plugins}/iCheck/flat/flat.css | 0 .../plugins => plugins}/iCheck/flat/flat.png | Bin .../iCheck/flat/flat@2x.png | Bin .../plugins => plugins}/iCheck/flat/green.css | 0 .../plugins => plugins}/iCheck/flat/green.png | Bin .../iCheck/flat/green@2x.png | Bin .../plugins => plugins}/iCheck/flat/grey.css | 0 .../plugins => plugins}/iCheck/flat/grey.png | Bin .../iCheck/flat/grey@2x.png | Bin .../iCheck/flat/orange.css | 0 .../iCheck/flat/orange.png | Bin .../iCheck/flat/orange@2x.png | Bin .../plugins => plugins}/iCheck/flat/pink.css | 0 .../plugins => plugins}/iCheck/flat/pink.png | Bin .../iCheck/flat/pink@2x.png | Bin .../iCheck/flat/purple.css | 0 .../iCheck/flat/purple.png | Bin .../iCheck/flat/purple@2x.png | Bin .../plugins => plugins}/iCheck/flat/red.css | 0 .../plugins => plugins}/iCheck/flat/red.png | Bin .../iCheck/flat/red@2x.png | Bin .../iCheck/flat/yellow.css | 0 .../iCheck/flat/yellow.png | Bin .../iCheck/flat/yellow@2x.png | Bin .../iCheck/futurico/futurico.css | 0 .../iCheck/futurico/futurico.png | Bin .../iCheck/futurico/futurico@2x.png | Bin {public/plugins => plugins}/iCheck/icheck.js | 0 .../plugins => plugins}/iCheck/icheck.min.js | 0 .../plugins => plugins}/iCheck/line/_all.css | 0 .../plugins => plugins}/iCheck/line/aero.css | 0 .../plugins => plugins}/iCheck/line/blue.css | 0 .../plugins => plugins}/iCheck/line/green.css | 0 .../plugins => plugins}/iCheck/line/grey.css | 0 .../plugins => plugins}/iCheck/line/line.css | 0 .../plugins => plugins}/iCheck/line/line.png | Bin .../iCheck/line/line@2x.png | Bin .../iCheck/line/orange.css | 0 .../plugins => plugins}/iCheck/line/pink.css | 0 .../iCheck/line/purple.css | 0 .../plugins => plugins}/iCheck/line/red.css | 0 .../iCheck/line/yellow.css | 0 .../iCheck/minimal/_all.css | 0 .../iCheck/minimal/aero.css | 0 .../iCheck/minimal/aero.png | Bin .../iCheck/minimal/aero@2x.png | Bin .../iCheck/minimal/blue.css | 0 .../iCheck/minimal/blue.png | Bin .../iCheck/minimal/blue@2x.png | Bin .../iCheck/minimal/green.css | 0 .../iCheck/minimal/green.png | Bin .../iCheck/minimal/green@2x.png | Bin .../iCheck/minimal/grey.css | 0 .../iCheck/minimal/grey.png | Bin .../iCheck/minimal/grey@2x.png | Bin .../iCheck/minimal/minimal.css | 0 .../iCheck/minimal/minimal.png | Bin .../iCheck/minimal/minimal@2x.png | Bin .../iCheck/minimal/orange.css | 0 .../iCheck/minimal/orange.png | Bin .../iCheck/minimal/orange@2x.png | Bin .../iCheck/minimal/pink.css | 0 .../iCheck/minimal/pink.png | Bin .../iCheck/minimal/pink@2x.png | Bin .../iCheck/minimal/purple.css | 0 .../iCheck/minimal/purple.png | Bin .../iCheck/minimal/purple@2x.png | Bin .../iCheck/minimal/red.css | 0 .../iCheck/minimal/red.png | Bin .../iCheck/minimal/red@2x.png | Bin .../iCheck/minimal/yellow.css | 0 .../iCheck/minimal/yellow.png | Bin .../iCheck/minimal/yellow@2x.png | Bin .../iCheck/polaris/polaris.css | 0 .../iCheck/polaris/polaris.png | Bin .../iCheck/polaris/polaris@2x.png | Bin .../iCheck/square/_all.css | 0 .../iCheck/square/aero.css | 0 .../iCheck/square/aero.png | Bin .../iCheck/square/aero@2x.png | Bin .../iCheck/square/blue.css | 0 .../iCheck/square/blue.png | Bin .../iCheck/square/blue@2x.png | Bin .../iCheck/square/green.css | 0 .../iCheck/square/green.png | Bin .../iCheck/square/green@2x.png | Bin .../iCheck/square/grey.css | 0 .../iCheck/square/grey.png | Bin .../iCheck/square/grey@2x.png | Bin .../iCheck/square/orange.css | 0 .../iCheck/square/orange.png | Bin .../iCheck/square/orange@2x.png | Bin .../iCheck/square/pink.css | 0 .../iCheck/square/pink.png | Bin .../iCheck/square/pink@2x.png | Bin .../iCheck/square/purple.css | 0 .../iCheck/square/purple.png | Bin .../iCheck/square/purple@2x.png | Bin .../plugins => plugins}/iCheck/square/red.css | 0 .../plugins => plugins}/iCheck/square/red.png | Bin .../iCheck/square/red@2x.png | Bin .../iCheck/square/square.css | 0 .../iCheck/square/square.png | Bin .../iCheck/square/square@2x.png | Bin .../iCheck/square/yellow.css | 0 .../iCheck/square/yellow.png | Bin .../iCheck/square/yellow@2x.png | Bin .../jquery.slimscroll.min.js | 0 .../plugins => plugins}/jquery/jquery.min.js | 0 public/.htaccess | 11 - public/index.php | 4 - routes.php | 8 - views/index.php | 44 - views/login.php | 43 - 262 files changed, 2322 insertions(+), 291 deletions(-) create mode 100644 .htaccess create mode 100644 README.MD create mode 100644 core/app/Controllers/AuthController.php create mode 100644 core/app/Controllers/Controller.php rename {app => core/app}/Controllers/ErrorController.php (96%) rename {app => core/app}/Controllers/IndexController.php (51%) create mode 100644 core/app/Controllers/UserController.php create mode 100644 core/app/Controllers/WebsiteController.php create mode 100644 core/app/Models/User.php create mode 100644 core/app/Models/Website.php create mode 100644 core/app/Validation/UniqueRule.php rename {bootstrap => core/bootstrap}/app.php (59%) create mode 100644 core/helpers.php create mode 100644 core/routes.php rename {views => core/views}/errors/404.php (100%) rename {views => core/views}/errors/405.php (100%) rename {views => core/views}/errors/500.php (100%) create mode 100644 core/views/index.php rename {views => core/views}/layouts/app.php (94%) rename {views => core/views}/layouts/auth.php (100%) rename {views => core/views}/layouts/footer.php (100%) rename {views => core/views}/layouts/navigation.php (62%) rename {views => core/views}/layouts/topnavbar.php (90%) create mode 100644 core/views/login.php rename {views => core/views}/register.php (100%) create mode 100644 core/views/users/index.php create mode 100644 core/views/users/store.php create mode 100644 core/views/users/update.php create mode 100644 core/views/websites/index.php create mode 100644 core/views/websites/store.php create mode 100644 core/views/websites/update.php rename {public/css => css}/AdminLTE.css (100%) rename {public/css => css}/AdminLTE.min.css (100%) rename {public/css => css}/alt/AdminLTE-bootstrap-social.css (100%) rename {public/css => css}/alt/AdminLTE-bootstrap-social.min.css (100%) rename {public/css => css}/alt/AdminLTE-fullcalendar.css (100%) rename {public/css => css}/alt/AdminLTE-fullcalendar.min.css (100%) rename {public/css => css}/alt/AdminLTE-select2.css (100%) rename {public/css => css}/alt/AdminLTE-select2.min.css (100%) rename {public/css => css}/alt/AdminLTE-without-plugins.css (100%) rename {public/css => css}/alt/AdminLTE-without-plugins.min.css (100%) rename {public/css => css}/skins/_all-skins.css (100%) rename {public/css => css}/skins/_all-skins.min.css (100%) rename {public/css => css}/skins/skin-black-light.css (100%) rename {public/css => css}/skins/skin-black-light.min.css (100%) rename {public/css => css}/skins/skin-black.css (100%) rename {public/css => css}/skins/skin-black.min.css (100%) rename {public/css => css}/skins/skin-blue-light.css (100%) rename {public/css => css}/skins/skin-blue-light.min.css (100%) rename {public/css => css}/skins/skin-blue.css (100%) rename {public/css => css}/skins/skin-blue.min.css (100%) rename {public/css => css}/skins/skin-green-light.css (100%) rename {public/css => css}/skins/skin-green-light.min.css (100%) rename {public/css => css}/skins/skin-green.css (100%) rename {public/css => css}/skins/skin-green.min.css (100%) rename {public/css => css}/skins/skin-purple-light.css (100%) rename {public/css => css}/skins/skin-purple-light.min.css (100%) rename {public/css => css}/skins/skin-purple.css (100%) rename {public/css => css}/skins/skin-purple.min.css (100%) rename {public/css => css}/skins/skin-red-light.css (100%) rename {public/css => css}/skins/skin-red-light.min.css (100%) rename {public/css => css}/skins/skin-red.css (100%) rename {public/css => css}/skins/skin-red.min.css (100%) rename {public/css => css}/skins/skin-yellow-light.css (100%) rename {public/css => css}/skins/skin-yellow-light.min.css (100%) rename {public/css => css}/skins/skin-yellow.css (100%) rename {public/css => css}/skins/skin-yellow.min.css (100%) create mode 100644 database.sql delete mode 100644 helpers.php rename {public/img => img}/avatar.png (100%) rename {public/img => img}/avatar04.png (100%) rename {public/img => img}/avatar2.png (100%) rename {public/img => img}/avatar3.png (100%) rename {public/img => img}/avatar5.png (100%) rename {public/img => img}/boxed-bg.jpg (100%) rename {public/img => img}/boxed-bg.png (100%) rename {public/img => img}/credit/american-express.png (100%) rename {public/img => img}/credit/cirrus.png (100%) rename {public/img => img}/credit/mastercard.png (100%) rename {public/img => img}/credit/mestro.png (100%) rename {public/img => img}/credit/paypal.png (100%) rename {public/img => img}/credit/paypal2.png (100%) rename {public/img => img}/credit/visa.png (100%) rename {public/img => img}/default-50x50.gif (100%) rename {public/img => img}/icons.png (100%) rename {public/img => img}/photo1.png (100%) rename {public/img => img}/photo2.png (100%) rename {public/img => img}/photo3.jpg (100%) rename {public/img => img}/photo4.jpg (100%) rename {public/img => img}/user1-128x128.jpg (100%) rename {public/img => img}/user2-160x160.jpg (100%) rename {public/img => img}/user3-128x128.jpg (100%) rename {public/img => img}/user4-128x128.jpg (100%) rename {public/img => img}/user5-128x128.jpg (100%) rename {public/img => img}/user6-128x128.jpg (100%) rename {public/img => img}/user7-128x128.jpg (100%) rename {public/img => img}/user8-128x128.jpg (100%) create mode 100644 index.php rename {public/js => js}/adminlte.js (100%) rename {public/js => js}/adminlte.min.js (100%) rename {public/js => js}/app.js (100%) rename {public/js => js}/app.min.js (100%) rename {public/js => js}/demo.js (100%) rename {public/js => js}/pages/dashboard.js (100%) rename {public/js => js}/pages/dashboard2.js (100%) rename {public/plugins => plugins}/Ionicons/css/ionicons.css (100%) rename {public/plugins => plugins}/Ionicons/css/ionicons.min.css (100%) rename {public/plugins => plugins}/Ionicons/fonts/ionicons.eot (100%) rename {public/plugins => plugins}/Ionicons/fonts/ionicons.svg (100%) rename {public/plugins => plugins}/Ionicons/fonts/ionicons.ttf (100%) rename {public/plugins => plugins}/Ionicons/fonts/ionicons.woff (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap-theme.css (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap-theme.css.map (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap-theme.min.css (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap-theme.min.css.map (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap.css (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap.css.map (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap.min.css (100%) rename {public/plugins => plugins}/bootstrap/css/bootstrap.min.css.map (100%) rename {public/plugins => plugins}/bootstrap/fonts/glyphicons-halflings-regular.eot (100%) rename {public/plugins => plugins}/bootstrap/fonts/glyphicons-halflings-regular.svg (100%) rename {public/plugins => plugins}/bootstrap/fonts/glyphicons-halflings-regular.ttf (100%) rename {public/plugins => plugins}/bootstrap/fonts/glyphicons-halflings-regular.woff (100%) rename {public/plugins => plugins}/bootstrap/fonts/glyphicons-halflings-regular.woff2 (100%) rename {public/plugins => plugins}/bootstrap/js/bootstrap.js (100%) rename {public/plugins => plugins}/bootstrap/js/bootstrap.min.js (100%) rename {public/plugins => plugins}/bootstrap/js/npm.js (100%) create mode 100644 plugins/clipboard.js/clipboard.min.js rename {public/plugins => plugins}/fastclick/fastclick.js (100%) rename {public/plugins => plugins}/font-awesome/css/font-awesome.css (100%) rename {public/plugins => plugins}/font-awesome/css/font-awesome.css.map (100%) rename {public/plugins => plugins}/font-awesome/css/font-awesome.min.css (100%) rename {public/plugins => plugins}/font-awesome/fonts/FontAwesome.otf (100%) rename {public/plugins => plugins}/font-awesome/fonts/fontawesome-webfont.eot (100%) rename {public/plugins => plugins}/font-awesome/fonts/fontawesome-webfont.svg (100%) rename {public/plugins => plugins}/font-awesome/fonts/fontawesome-webfont.ttf (100%) rename {public/plugins => plugins}/font-awesome/fonts/fontawesome-webfont.woff (100%) rename {public/plugins => plugins}/font-awesome/fonts/fontawesome-webfont.woff2 (100%) rename {public/plugins => plugins}/iCheck/all.css (100%) rename {public/plugins => plugins}/iCheck/flat/_all.css (100%) rename {public/plugins => plugins}/iCheck/flat/aero.css (100%) rename {public/plugins => plugins}/iCheck/flat/aero.png (100%) rename {public/plugins => plugins}/iCheck/flat/aero@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/blue.css (100%) rename {public/plugins => plugins}/iCheck/flat/blue.png (100%) rename {public/plugins => plugins}/iCheck/flat/blue@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/flat.css (100%) rename {public/plugins => plugins}/iCheck/flat/flat.png (100%) rename {public/plugins => plugins}/iCheck/flat/flat@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/green.css (100%) rename {public/plugins => plugins}/iCheck/flat/green.png (100%) rename {public/plugins => plugins}/iCheck/flat/green@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/grey.css (100%) rename {public/plugins => plugins}/iCheck/flat/grey.png (100%) rename {public/plugins => plugins}/iCheck/flat/grey@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/orange.css (100%) rename {public/plugins => plugins}/iCheck/flat/orange.png (100%) rename {public/plugins => plugins}/iCheck/flat/orange@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/pink.css (100%) rename {public/plugins => plugins}/iCheck/flat/pink.png (100%) rename {public/plugins => plugins}/iCheck/flat/pink@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/purple.css (100%) rename {public/plugins => plugins}/iCheck/flat/purple.png (100%) rename {public/plugins => plugins}/iCheck/flat/purple@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/red.css (100%) rename {public/plugins => plugins}/iCheck/flat/red.png (100%) rename {public/plugins => plugins}/iCheck/flat/red@2x.png (100%) rename {public/plugins => plugins}/iCheck/flat/yellow.css (100%) rename {public/plugins => plugins}/iCheck/flat/yellow.png (100%) rename {public/plugins => plugins}/iCheck/flat/yellow@2x.png (100%) rename {public/plugins => plugins}/iCheck/futurico/futurico.css (100%) rename {public/plugins => plugins}/iCheck/futurico/futurico.png (100%) rename {public/plugins => plugins}/iCheck/futurico/futurico@2x.png (100%) rename {public/plugins => plugins}/iCheck/icheck.js (100%) rename {public/plugins => plugins}/iCheck/icheck.min.js (100%) rename {public/plugins => plugins}/iCheck/line/_all.css (100%) rename {public/plugins => plugins}/iCheck/line/aero.css (100%) rename {public/plugins => plugins}/iCheck/line/blue.css (100%) rename {public/plugins => plugins}/iCheck/line/green.css (100%) rename {public/plugins => plugins}/iCheck/line/grey.css (100%) rename {public/plugins => plugins}/iCheck/line/line.css (100%) rename {public/plugins => plugins}/iCheck/line/line.png (100%) rename {public/plugins => plugins}/iCheck/line/line@2x.png (100%) rename {public/plugins => plugins}/iCheck/line/orange.css (100%) rename {public/plugins => plugins}/iCheck/line/pink.css (100%) rename {public/plugins => plugins}/iCheck/line/purple.css (100%) rename {public/plugins => plugins}/iCheck/line/red.css (100%) rename {public/plugins => plugins}/iCheck/line/yellow.css (100%) rename {public/plugins => plugins}/iCheck/minimal/_all.css (100%) rename {public/plugins => plugins}/iCheck/minimal/aero.css (100%) rename {public/plugins => plugins}/iCheck/minimal/aero.png (100%) rename {public/plugins => plugins}/iCheck/minimal/aero@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/blue.css (100%) rename {public/plugins => plugins}/iCheck/minimal/blue.png (100%) rename {public/plugins => plugins}/iCheck/minimal/blue@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/green.css (100%) rename {public/plugins => plugins}/iCheck/minimal/green.png (100%) rename {public/plugins => plugins}/iCheck/minimal/green@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/grey.css (100%) rename {public/plugins => plugins}/iCheck/minimal/grey.png (100%) rename {public/plugins => plugins}/iCheck/minimal/grey@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/minimal.css (100%) rename {public/plugins => plugins}/iCheck/minimal/minimal.png (100%) rename {public/plugins => plugins}/iCheck/minimal/minimal@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/orange.css (100%) rename {public/plugins => plugins}/iCheck/minimal/orange.png (100%) rename {public/plugins => plugins}/iCheck/minimal/orange@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/pink.css (100%) rename {public/plugins => plugins}/iCheck/minimal/pink.png (100%) rename {public/plugins => plugins}/iCheck/minimal/pink@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/purple.css (100%) rename {public/plugins => plugins}/iCheck/minimal/purple.png (100%) rename {public/plugins => plugins}/iCheck/minimal/purple@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/red.css (100%) rename {public/plugins => plugins}/iCheck/minimal/red.png (100%) rename {public/plugins => plugins}/iCheck/minimal/red@2x.png (100%) rename {public/plugins => plugins}/iCheck/minimal/yellow.css (100%) rename {public/plugins => plugins}/iCheck/minimal/yellow.png (100%) rename {public/plugins => plugins}/iCheck/minimal/yellow@2x.png (100%) rename {public/plugins => plugins}/iCheck/polaris/polaris.css (100%) rename {public/plugins => plugins}/iCheck/polaris/polaris.png (100%) rename {public/plugins => plugins}/iCheck/polaris/polaris@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/_all.css (100%) rename {public/plugins => plugins}/iCheck/square/aero.css (100%) rename {public/plugins => plugins}/iCheck/square/aero.png (100%) rename {public/plugins => plugins}/iCheck/square/aero@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/blue.css (100%) rename {public/plugins => plugins}/iCheck/square/blue.png (100%) rename {public/plugins => plugins}/iCheck/square/blue@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/green.css (100%) rename {public/plugins => plugins}/iCheck/square/green.png (100%) rename {public/plugins => plugins}/iCheck/square/green@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/grey.css (100%) rename {public/plugins => plugins}/iCheck/square/grey.png (100%) rename {public/plugins => plugins}/iCheck/square/grey@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/orange.css (100%) rename {public/plugins => plugins}/iCheck/square/orange.png (100%) rename {public/plugins => plugins}/iCheck/square/orange@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/pink.css (100%) rename {public/plugins => plugins}/iCheck/square/pink.png (100%) rename {public/plugins => plugins}/iCheck/square/pink@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/purple.css (100%) rename {public/plugins => plugins}/iCheck/square/purple.png (100%) rename {public/plugins => plugins}/iCheck/square/purple@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/red.css (100%) rename {public/plugins => plugins}/iCheck/square/red.png (100%) rename {public/plugins => plugins}/iCheck/square/red@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/square.css (100%) rename {public/plugins => plugins}/iCheck/square/square.png (100%) rename {public/plugins => plugins}/iCheck/square/square@2x.png (100%) rename {public/plugins => plugins}/iCheck/square/yellow.css (100%) rename {public/plugins => plugins}/iCheck/square/yellow.png (100%) rename {public/plugins => plugins}/iCheck/square/yellow@2x.png (100%) rename {public/plugins => plugins}/jquery-slimscroll/jquery.slimscroll.min.js (100%) rename {public/plugins => plugins}/jquery/jquery.min.js (100%) delete mode 100644 public/.htaccess delete mode 100644 public/index.php delete mode 100644 routes.php delete mode 100644 views/index.php delete mode 100644 views/login.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..aa5de85 --- /dev/null +++ b/.htaccess @@ -0,0 +1,26 @@ + + RewriteEngine On + + # Redirect Trailing Slashes... + RewriteRule ^(.*)/$ /$1 [L,R=301] + + # Handle Front Controller... + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + + +# Disable Directory listing +Options -Indexes + +# block files which needs to be hidden // in here specify .example extension of the file + + Order allow,deny + Deny from all + + +# in here specify full file name sperator '|' + + Order allow,deny + Deny from all + \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..8c46d06 --- /dev/null +++ b/README.MD @@ -0,0 +1,49 @@ +# Pig Framework + +### Custom framework with PHP packages + +Notice: This project not Good. So, I use it for myself ;) + +## 1. How to setup this project + +- Just create database and import file database.sql +``` +Username: admin +Password: admin +``` +- Change correct infomation about Username & Password MYSQL in file .env +``` +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=PigFramework +DB_USERNAME=root +DB_PASSWORD=secret +``` +- Change APP_URL and APP_NAME in file .env, +``` +APP_NAME='Pig Framework' +APP_DEBUG=true +APP_URL=http://localhost:8000 +``` +- APP_DEBUG above true if you want show error, false if not. + + +## 2. Some package I use in this project: +- [nikic/fast-route](https://github.com/nikic/FastRoute): Route +- [league/container](https://github.com/thephpleague/container): Manage container +- [symfony/http-foundation](https://github.com/symfony/http-foundation): Request, Response +- [filp/whoops](https://github.com/filp/whoops): Manage error message +- [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv): .env file +- [league/plates](https://github.com/thephpleague/plates): Native PHP template +- [illuminate/database](https://github.com/illuminate/database): Database Eloquent like Laravel +- [rakit/validation](https://github.com/rakit/validation): Validate Input +- [jasongrimes/paginator](https://github.com/jasongrimes/php-paginator): Paginator ;) + +### I use [AdminLTE](https://adminlte.io/themes/AdminLTE/index2.html) for UI. I Love this UI. + +Thanks + +I'm lazy. So, Just use package :D + +Have a great day ;) \ No newline at end of file diff --git a/composer.json b/composer.json index 4e9b79a..25deda3 100644 --- a/composer.json +++ b/composer.json @@ -2,19 +2,23 @@ "name": "trungpv1601/PigFramework", "description": "Custom framework with PHP packages", "require": { - "nikic/fast-route": "^1.0", - "league/container": "^2.2", - "symfony/http-foundation": "^3.2", - "symfony/var-dumper": "^3.2", + "nikic/fast-route": "^1.3", + "league/container": "^3.2", + "symfony/http-foundation": "^3.4", + "symfony/var-dumper": "^3.4", "filp/whoops": "^2.1", - "vlucas/phpdotenv": "^2.4", - "catfan/Medoo": "^1.4", - "league/plates": "^3.3" + "vlucas/phpdotenv": "^2.5", + "league/plates": "^3.3", + "illuminate/database": "5.1.8", + "rakit/validation": "^0.18.1", + "jasongrimes/paginator": "^1.0", + "fzaninotto/faker": "^1.8", + "nesbot/carbon": "^1.33" }, "autoload": { "psr-4": { - "App\\": "app/" + "App\\": "core/app/" }, - "files" : ["helpers.php"] + "files" : ["core/helpers.php"] } } diff --git a/composer.lock b/composer.lock index 4c429c5..9e7f3bd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,40 +4,37 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "5fc1fc472b9875fcc857aae32d3287b1", + "content-hash": "17c3821a99b6059f5858f3c0b20ebfd5", "packages": [ { - "name": "catfan/medoo", - "version": "v1.4.5", + "name": "danielstjules/stringy", + "version": "1.10.0", "source": { "type": "git", - "url": "https://github.com/catfan/Medoo.git", - "reference": "8ee8ae1c4df0fee3822a01333eab88893e548fcc" + "url": "https://github.com/danielstjules/Stringy.git", + "reference": "4749c205db47ee5b32e8d1adf6d9aff8db6caf3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/catfan/Medoo/zipball/8ee8ae1c4df0fee3822a01333eab88893e548fcc", - "reference": "8ee8ae1c4df0fee3822a01333eab88893e548fcc", + "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/4749c205db47ee5b32e8d1adf6d9aff8db6caf3b", + "reference": "4749c205db47ee5b32e8d1adf6d9aff8db6caf3b", "shasum": "" }, "require": { - "ext-pdo": "*", - "php": ">=5.4" + "ext-mbstring": "*", + "php": ">=5.3.0" }, - "suggest": { - "ext-pdo_dblib": "For MSSQL or Sybase database on Linux/UNIX platform", - "ext-pdo_mysql": "For MySQL or MariaDB database", - "ext-pdo_oci": "For Oracle database", - "ext-pdo_oci8": "For Oracle version 8 database", - "ext-pdo_pqsql": "For PostgreSQL database", - "ext-pdo_sqlite": "For SQLite database", - "ext-pdo_sqlsrv": "For MSSQL database on Windows platform" - }, - "type": "framework", + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", "autoload": { "psr-4": { - "Medoo\\": "/src" - } + "Stringy\\": "src/" + }, + "files": [ + "src/Create.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -45,69 +42,105 @@ ], "authors": [ { - "name": "Angel Lai", - "email": "angel@catfan.me" + "name": "Daniel St. Jules", + "email": "danielst.jules@gmail.com", + "homepage": "http://www.danielstjules.com" } ], - "description": "The lightest PHP database framework to accelerate development", - "homepage": "https://medoo.in", + "description": "A string manipulation library with multibyte support", + "homepage": "https://github.com/danielstjules/Stringy", "keywords": [ - "database", - "lightweight", - "mariadb", - "mssql", - "mysql", - "oracle", - "php framework", - "postgresql", - "sql", - "sqlite" - ], - "time": "2017-06-24T14:43:07+00:00" + "UTF", + "helpers", + "manipulation", + "methods", + "multibyte", + "string", + "utf-8", + "utility", + "utils" + ], + "time": "2015-07-23T00:54:12+00:00" }, { - "name": "container-interop/container-interop", - "version": "1.2.0", + "name": "doctrine/inflector", + "version": "v1.3.0", "source": { "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" + "url": "https://github.com/doctrine/inflector.git", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a", "shasum": "" }, "require": { - "psr/container": "^1.0" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, "autoload": { "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "homepage": "https://github.com/container-interop/container-interop", - "time": "2017-02-14T19:40:03+00:00" + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2018-01-09T20:05:19+00:00" }, { "name": "filp/whoops", - "version": "2.1.9", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f" + "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f", - "reference": "b238974e1c7cc1859b0c16ddc1c02ecb70ecc07f", + "url": "https://api.github.com/repos/filp/whoops/zipball/181c4502d8f34db7aed7bfe88d4f87875b8e947a", + "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a", "shasum": "" }, "require": { @@ -115,9 +148,9 @@ "psr/log": "^1.0.1" }, "require-dev": { - "mockery/mockery": "0.9.*", - "phpunit/phpunit": "^4.8 || ^5.0", - "symfony/var-dumper": "^2.6 || ^3.0" + "mockery/mockery": "^0.9 || ^1.0", + "phpunit/phpunit": "^4.8.35 || ^5.7", + "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0" }, "suggest": { "symfony/var-dumper": "Pretty print complex values better with var-dumper available", @@ -126,7 +159,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -152,42 +185,336 @@ "exception", "handling", "library", - "whoops", - "zf2" + "throwable", + "whoops" + ], + "time": "2018-03-03T17:56:25+00:00" + }, + { + "name": "fzaninotto/faker", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/fzaninotto/Faker.git", + "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/f72816b43e74063c8b10357394b6bba8cb1c10de", + "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "ext-intl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7", + "squizlabs/php_codesniffer": "^1.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2018-07-12T10:23:15+00:00" + }, + { + "name": "illuminate/container", + "version": "v5.1.41", + "source": { + "type": "git", + "url": "https://github.com/illuminate/container.git", + "reference": "237de3cedbca9b753f2ee69bc7145ae159b8cc96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/container/zipball/237de3cedbca9b753f2ee69bc7145ae159b8cc96", + "reference": "237de3cedbca9b753f2ee69bc7145ae159b8cc96", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.1.*", + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Container\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" ], - "time": "2017-06-03T18:33:07+00:00" + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Container package.", + "homepage": "http://laravel.com", + "time": "2016-06-14T13:37:44+00:00" + }, + { + "name": "illuminate/contracts", + "version": "v5.1.41", + "source": { + "type": "git", + "url": "https://github.com/illuminate/contracts.git", + "reference": "6e828a355b7a467232efad3dbe76df17463178e3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/6e828a355b7a467232efad3dbe76df17463178e3", + "reference": "6e828a355b7a467232efad3dbe76df17463178e3", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Contracts\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Contracts package.", + "homepage": "http://laravel.com", + "time": "2015-09-24T11:16:48+00:00" + }, + { + "name": "illuminate/database", + "version": "v5.1.8", + "source": { + "type": "git", + "url": "https://github.com/illuminate/database.git", + "reference": "ad33fd28df334f248b97cd7ffd747b78635ec0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/database/zipball/ad33fd28df334f248b97cd7ffd747b78635ec0c4", + "reference": "ad33fd28df334f248b97cd7ffd747b78635ec0c4", + "shasum": "" + }, + "require": { + "illuminate/container": "5.1.*", + "illuminate/contracts": "5.1.*", + "illuminate/support": "5.1.*", + "nesbot/carbon": "~1.19", + "php": ">=5.5.9" + }, + "suggest": { + "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", + "fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).", + "illuminate/console": "Required to use the database commands (5.1.*).", + "illuminate/events": "Required to use the observers with Eloquent (5.1.*).", + "illuminate/filesystem": "Required to use the migrations (5.1.*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Database\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Database package.", + "homepage": "http://laravel.com", + "keywords": [ + "database", + "laravel", + "orm", + "sql" + ], + "time": "2015-07-20T16:50:34+00:00" + }, + { + "name": "illuminate/support", + "version": "v5.1.41", + "source": { + "type": "git", + "url": "https://github.com/illuminate/support.git", + "reference": "510163046dc50a467621448d6905f0c819ee8b4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/support/zipball/510163046dc50a467621448d6905f0c819ee8b4a", + "reference": "510163046dc50a467621448d6905f0c819ee8b4a", + "shasum": "" + }, + "require": { + "danielstjules/stringy": "~1.8", + "doctrine/inflector": "~1.0", + "ext-mbstring": "*", + "illuminate/contracts": "5.1.*", + "paragonie/random_compat": "~1.4", + "php": ">=5.5.9" + }, + "suggest": { + "jeremeamia/superclosure": "Required to be able to serialize closures (~2.0).", + "symfony/var-dumper": "Improves the dd function (2.7.*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "The Illuminate Support package.", + "homepage": "http://laravel.com", + "time": "2016-06-11T16:44:59+00:00" + }, + { + "name": "jasongrimes/paginator", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/jasongrimes/php-paginator.git", + "reference": "3411e3cd0c6479a0b514f26e4358f0273552f221" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jasongrimes/php-paginator/zipball/3411e3cd0c6479a0b514f26e4358f0273552f221", + "reference": "3411e3cd0c6479a0b514f26e4358f0273552f221", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "autoload": { + "psr-0": { + "JasonGrimes": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jason Grimes", + "email": "jason@grimesit.com" + } + ], + "description": "A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.", + "homepage": "http://github.com/jasongrimes/php-paginator", + "keywords": [ + "pager", + "pagination", + "paginator" + ], + "time": "2018-07-11T18:11:49+00:00" }, { "name": "league/container", - "version": "2.4.1", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/thephpleague/container.git", - "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0" + "reference": "4de774704c3a83d1bb3f1b5f2bbb116ac6ced315" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/container/zipball/43f35abd03a12977a60ffd7095efd6a7808488c0", - "reference": "43f35abd03a12977a60ffd7095efd6a7808488c0", + "url": "https://api.github.com/repos/thephpleague/container/zipball/4de774704c3a83d1bb3f1b5f2bbb116ac6ced315", + "reference": "4de774704c3a83d1bb3f1b5f2bbb116ac6ced315", "shasum": "" }, "require": { - "container-interop/container-interop": "^1.2", - "php": "^5.4.0 || ^7.0" + "php": "^7.0", + "psr/container": "^1.0" }, "provide": { - "container-interop/container-interop-implementation": "^1.2", "psr/container-implementation": "^1.0" }, "replace": { "orno/di": "~2.0" }, "require-dev": { - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.3" }, "type": "library", "extra": { "branch-alias": { + "dev-3.x": "3.x-dev", "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } @@ -220,7 +547,7 @@ "provider", "service" ], - "time": "2017-05-10T09:20:27+00:00" + "time": "2018-08-13T10:41:41+00:00" }, { "name": "league/plates", @@ -277,23 +604,81 @@ ], "time": "2016-12-28T00:14:17+00:00" }, + { + "name": "nesbot/carbon", + "version": "1.33.0", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "55667c1007a99e82030874b1bb14d24d07108413" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/55667c1007a99e82030874b1bb14d24d07108413", + "reference": "55667c1007a99e82030874b1bb14d24d07108413", + "shasum": "" + }, + "require": { + "php": ">=5.3.9", + "symfony/translation": "~2.6 || ~3.0 || ~4.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "^4.8.35 || ^5.7" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Carbon\\Laravel\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2018-08-07T08:39:47+00:00" + }, { "name": "nikic/fast-route", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/nikic/FastRoute.git", - "reference": "b5f95749071c82a8e0f58586987627054400cdf6" + "reference": "181d480e08d9476e61381e04a71b34dc0432e812" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/FastRoute/zipball/b5f95749071c82a8e0f58586987627054400cdf6", - "reference": "b5f95749071c82a8e0f58586987627054400cdf6", + "url": "https://api.github.com/repos/nikic/FastRoute/zipball/181d480e08d9476e61381e04a71b34dc0432e812", + "reference": "181d480e08d9476e61381e04a71b34dc0432e812", "shasum": "" }, "require": { "php": ">=5.4.0" }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|~5.7" + }, "type": "library", "autoload": { "psr-4": { @@ -318,7 +703,55 @@ "router", "routing" ], - "time": "2017-01-19T11:35:12+00:00" + "time": "2018-02-13T20:26:39+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v1.4.3", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/9b3899e3c3ddde89016f576edb8c489708ad64cd", + "reference": "9b3899e3c3ddde89016f576edb8c489708ad64cd", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "pseudorandom", + "random" + ], + "time": "2018-04-04T21:48:54+00:00" }, { "name": "psr/container", @@ -416,31 +849,71 @@ ], "time": "2016-10-10T12:19:37+00:00" }, + { + "name": "rakit/validation", + "version": "v0.18.1", + "source": { + "type": "git", + "url": "https://github.com/rakit/validation.git", + "reference": "402afc8c47681b37e933a7d85cd5f5dda5fd50a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rakit/validation/zipball/402afc8c47681b37e933a7d85cd5f5dda5fd50a0", + "reference": "402afc8c47681b37e933a7d85cd5f5dda5fd50a0", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Rakit\\Validation\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Muhammad Syifa", + "email": "emsifa@gmail.com" + } + ], + "description": "PHP Laravel like standalone validation library", + "time": "2018-08-22T12:16:10+00:00" + }, { "name": "symfony/http-foundation", - "version": "v3.3.4", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "f347a5f561b03db95ed666959db42bbbf429b7e5" + "reference": "2fb33cb6eefe6e790e4023f7c534a9e4214252fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/f347a5f561b03db95ed666959db42bbbf429b7e5", - "reference": "f347a5f561b03db95ed666959db42bbbf429b7e5", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/2fb33cb6eefe6e790e4023f7c534a9e4214252fc", + "reference": "2fb33cb6eefe6e790e4023f7c534a9e4214252fc", "shasum": "" }, "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.1" + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.1", + "symfony/polyfill-php70": "~1.6" }, "require-dev": { - "symfony/expression-language": "~2.8|~3.0" + "symfony/expression-language": "~2.8|~3.0|~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -467,20 +940,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2017-06-24T09:29:48+00:00" + "time": "2018-08-27T17:45:33+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.4.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "f29dca382a6485c3cbe6379f0c61230167681937" + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f29dca382a6485c3cbe6379f0c61230167681937", - "reference": "f29dca382a6485c3cbe6379f0c61230167681937", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -492,7 +965,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -526,24 +999,152 @@ "portable", "shim" ], - "time": "2017-06-09T14:24:12+00:00" + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.9.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "1e24b0c4a56d55aaf368763a06c6d1c7d3194934" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/1e24b0c4a56d55aaf368763a06c6d1c7d3194934", + "reference": "1e24b0c4a56d55aaf368763a06c6d1c7d3194934", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0|~9.99", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "symfony/translation", + "version": "v4.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "fa2182669f7983b7aa5f1a770d053f79f0ef144f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/fa2182669f7983b7aa5f1a770d053f79f0ef144f", + "reference": "fa2182669f7983b7aa5f1a770d053f79f0ef144f", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<3.4", + "symfony/dependency-injection": "<3.4", + "symfony/yaml": "<3.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/console": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/finder": "~2.8|~3.0|~4.0", + "symfony/intl": "~3.4|~4.0", + "symfony/yaml": "~3.4|~4.0" + }, + "suggest": { + "psr/log-implementation": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2018-08-07T12:45:11+00:00" }, { "name": "symfony/var-dumper", - "version": "v3.3.4", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "9ee920bba1d2ce877496dcafca7cbffff4dbe08a" + "reference": "f62a394bd3de96f2f5e8f4c7d685035897fb3cb3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/9ee920bba1d2ce877496dcafca7cbffff4dbe08a", - "reference": "9ee920bba1d2ce877496dcafca7cbffff4dbe08a", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/f62a394bd3de96f2f5e8f4c7d685035897fb3cb3", + "reference": "f62a394bd3de96f2f5e8f4c7d685035897fb3cb3", "shasum": "" }, "require": { - "php": ">=5.5.9", + "php": "^5.5.9|>=7.0.8", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -555,12 +1156,13 @@ }, "suggest": { "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", "ext-symfony_debug": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -594,32 +1196,32 @@ "debug", "dump" ], - "time": "2017-07-05T13:02:37+00:00" + "time": "2018-07-26T11:19:56+00:00" }, { "name": "vlucas/phpdotenv", - "version": "v2.4.0", + "version": "v2.5.1", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c" + "reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c", - "reference": "3cc116adbe4b11be5ec557bf1d24dc5e3a21d18c", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e", + "reference": "8abb4f9aa89ddea9d52112c65bbe8d0125e2fa8e", "shasum": "" }, "require": { "php": ">=5.3.9" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" + "phpunit/phpunit": "^4.8.35 || ^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } }, "autoload": { @@ -629,7 +1231,7 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause-Attribution" + "BSD-3-Clause" ], "authors": [ { @@ -644,7 +1246,7 @@ "env", "environment" ], - "time": "2016-09-01T10:05:43+00:00" + "time": "2018-07-29T20:33:41+00:00" } ], "packages-dev": [], diff --git a/core/app/Controllers/AuthController.php b/core/app/Controllers/AuthController.php new file mode 100644 index 0000000..2d5f880 --- /dev/null +++ b/core/app/Controllers/AuthController.php @@ -0,0 +1,110 @@ +view = $view; + $this->request = Request::createFromGlobals(); + $this->rules = [ + 'username' => 'required', + 'password' => 'required' + ]; + $this->session = $session; + } + + /** + * Login page + * + * @return Response + */ + public function login() + { + return new Response($this->view->render('login')); + } + + /** + * POST Login Page + */ + public function loginPOST() + { + if(is_csrf_token()){ + $params = $this->request->request->all(); + + $validator = new Validator(); + + // make it + $validation = $validator->make($params, $this->rules); + + // then validate + $validation->validate(); + + if ($validation->fails()) { + // handling errors + $errors = $validation->errors(); + return new Response($this->view->render('login', ['errors' => $errors, 'request' => $this->request])); + } else { + // validation passes + $user = $this->validAuth($params['username'], $params['password']); + if(!$user){ + $username = 'Wrong username & password.'; + return new Response($this->view->render('login', ['username' => $username, 'request' => $this->request])); + } + + $this->session->set('user', $user); + return new RedirectResponse(url('/')); + } + } else { + return new RedirectResponse(lastUrl('/')); + } + } + + /** + * Register page + * + * @return Response + */ + public function register() + { + return new Response($this->view->render('register')); + } + + public function logout() + { + if(is_csrf_token()){ + $this->session->remove('user'); + return new RedirectResponse(url('/login')); + }else{ + return new RedirectResponse(url('/')); + } + } + + private function validAuth($username, $password) + { + $user = User::where('username', $username)->where('password', md5($password))->first(); + if($user){ + return $user; + } + return false; + } +} \ No newline at end of file diff --git a/core/app/Controllers/Controller.php b/core/app/Controllers/Controller.php new file mode 100644 index 0000000..ae1ec8a --- /dev/null +++ b/core/app/Controllers/Controller.php @@ -0,0 +1,14 @@ + */ -class IndexController +class IndexController extends Controller { private $view; - private $database; + private $request; + private $session; /** * IndexController, constructed by the container * * @param Engine $view */ - public function __construct(Engine $view, Medoo $database) + public function __construct(Engine $view, Session $session) { $this->view = $view; - $this->database = $database; + $this->request = Request::createFromGlobals(); + $this->session = $session; } /** @@ -34,27 +38,7 @@ public function __construct(Engine $view, Medoo $database) */ public function index() { - return new Response($this->view->render('index')); - } - - /** - * Login page - * - * @return Response - */ - public function login() - { - return new Response($this->view->render('login')); - } - - /** - * Register page - * - * @return Response - */ - public function register() - { - return new Response($this->view->render('register')); + return new Response($this->view->render('index', ['request' => $this->request])); } /** diff --git a/core/app/Controllers/UserController.php b/core/app/Controllers/UserController.php new file mode 100644 index 0000000..9ed8a04 --- /dev/null +++ b/core/app/Controllers/UserController.php @@ -0,0 +1,207 @@ +view = $view; + $this->request = Request::createFromGlobals(); + $this->rules = [ + 'name' => 'required', + 'username' => 'required|unique:users,username', + 'password' => 'required' + ]; + $this->session = $session; + } + + /** + * Index page + * + * @return Response + */ + public function index() + { + $itemsPerPage = 10; + $currentPage = $this->request->query->has('page') ? $this->request->query->get('page') : 1; + $users = User::offset(($currentPage - 1) * $itemsPerPage)->limit($itemsPerPage); + $urlPattern = '/users?page=(:num)'; + + // Filter + if($this->request->query->has('name')){ + $name = $this->request->query->get('name'); + $totalItems = User::where('name', 'like', '%' . $name . '%'); + $users = $users->where('name', 'like', '%' . $name . '%'); + $urlPattern = $urlPattern . '&name=' . $name; + } + + if($this->request->query->has('username')){ + $username = $this->request->query->get('username'); + $totalItems = $totalItems->where('username', 'like', '%' . $username . '%'); + $users = $users->where('username', 'like', '%' . $username . '%'); + $urlPattern = $urlPattern . '&username=' . $username; + } + + if($this->request->query->has('is_admin') && $this->request->query->get('is_admin') != -1){ + $is_admin = $this->request->query->get('is_admin'); + $totalItems = $totalItems->where('is_admin', $is_admin); + $users = $users->where('is_admin', $is_admin); + $urlPattern = $urlPattern . '&is_admin=' . $is_admin; + } + + if(!isset($totalItems)){ + $totalItems = User::count(); + }else{ + $totalItems = $totalItems->count(); + } + $users = $users->orderBy('id', 'desc')->get(); + + $paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern); + + return new Response($this->view->render('users/index', ['request' => $this->request, 'users' => $users, 'paginator' => $paginator, 'itemsPerPage' => $itemsPerPage])); + } + + /** + * Add page + * + * @return Response + */ + public function store() + { + // $faker = \Faker\Factory::create(); + // $this->request->request->set('name', $faker->name); + // $this->request->request->set('username', $faker->username); + // $this->request->request->set('password', $faker->password); + return new Response($this->view->render('users/store', ['request' => $this->request])); + } + + /** + * POST Add page + */ + public function storePost() + { + if(is_csrf_token()){ + $params = $this->request->request->all(); + + $validator = new Validator; + $validator->addValidator('unique', new UniqueRule()); + + // make it + $validation = $validator->make($params, $this->rules); + + // then validate + $validation->validate(); + + if ($validation->fails()) { + // handling errors + $errors = $validation->errors(); + return new Response($this->view->render('users/store', ['errors' => $errors, 'request' => $this->request])); + } else { + // validation passes + $user = new User(); + $user->name = $params['name']; + $user->username = $params['username']; + $user->password = md5($params['password']); + $user->is_admin = $this->request->request->has('is_admin') ? true : false; + $user->save(); + + return new RedirectResponse(url('/users')); + } + } else { + return new RedirectResponse(lastUrl('/')); + } + } + + /** + * Update page + * + * @return Response + */ + public function update($id) + { + $user = User::find($id)->first(); + return new Response($this->view->render('users/update', ['user' => $user])); + } + + /** + * POST Update page + */ + public function updatePost($id) + { + if(is_csrf_token()){ + $user = User::find($id)->first(); + $params = $this->request->request->all(); + + $validator = new Validator; + $validator->addValidator('unique', new UniqueRule()); + + $this->rules['username'] = 'required|unique:users,username,' . $user->username; + $this->rules['old_password'] = 'required'; + $this->rules['password'] = ''; + + // make it + $validation = $validator->make($params, $this->rules); + + // then validate + $validation->validate(); + + if ($validation->fails()) { + // handling errors + $errors = $validation->errors(); + return new Response($this->view->render('users/update', ['errors' => $errors, 'user' => $user])); + } else { + // validation passes + if($user->password === md5($params['old_password'])){ + $user->name = $params['name']; + $user->username = $params['username']; + $user->password = md5($params['password']); + $user->is_admin = $this->request->request->has('is_admin') ? true : false; + $user->save(); + + return new RedirectResponse($params['previous']); + } + $old_password = 'Please enter correct old password.'; + + return new Response($this->view->render('users/update', ['old_password' => $old_password, 'user' => $user])); + } + } else { + return new RedirectResponse(lastUrl('/')); + } + } + + /** + * POST Delete + */ + public function delete($id) + { + if(is_csrf_token()){ + $user = User::destroy($id); + } + return new RedirectResponse(lastUrl('/')); + } +} diff --git a/core/app/Controllers/WebsiteController.php b/core/app/Controllers/WebsiteController.php new file mode 100644 index 0000000..e4177ae --- /dev/null +++ b/core/app/Controllers/WebsiteController.php @@ -0,0 +1,194 @@ +view = $view; + $this->request = Request::createFromGlobals(); + $this->rules = [ + 'name' => 'required', + 'link' => 'required|unique:websites,link' + ]; + $this->session = $session; + } + + /** + * Index page + * + * @return Response + */ + public function index() + { + $itemsPerPage = 10; + $currentPage = $this->request->query->has('page') ? $this->request->query->get('page') : 1; + $websites = Website::offset(($currentPage - 1) * $itemsPerPage)->limit($itemsPerPage); + $urlPattern = '/websites?page=(:num)'; + + // Filter + if($this->request->query->has('name')){ + $name = $this->request->query->get('name'); + $totalItems = Website::where('name', 'like', '%' . $name . '%'); + $websites = $websites->where('name', 'like', '%' . $name . '%'); + $urlPattern = $urlPattern . '&name=' . $name; + } + + if($this->request->query->has('link')){ + $link = $this->request->query->get('link'); + $totalItems = $totalItems->where('link', 'like', '%' . $link . '%'); + $websites = $websites->where('link', 'like', '%' . $link . '%'); + $urlPattern = $urlPattern . '&link=' . $link; + } + + if(!isset($totalItems)){ + $totalItems = Website::count(); + }else{ + $totalItems = $totalItems->count(); + } + $websites = $websites->orderBy('id', 'desc')->get(); + + $paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern); + + return new Response($this->view->render('websites/index', ['request' => $this->request, 'websites' => $websites, 'paginator' => $paginator, 'itemsPerPage' => $itemsPerPage])); + } + + /** + * Add page + * + * @return Response + */ + public function store() + { + // $faker = \Faker\Factory::create(); + // $this->request->request->set('name', $faker->name); + // $this->request->request->set('link', $faker->domainName); + // $this->request->request->set('xpath', $faker->name); + return new Response($this->view->render('websites/store', ['request' => $this->request])); + } + + /** + * POST Add page + */ + public function storePost() + { + if(is_csrf_token()){ + $params = $this->request->request->all(); + + $validator = new Validator; + $validator->addValidator('unique', new UniqueRule()); + + // make it + $validation = $validator->make($params, $this->rules); + + // then validate + $validation->validate(); + + if ($validation->fails()) { + // handling errors + $errors = $validation->errors(); + return new Response($this->view->render('websites/store', ['errors' => $errors, 'request' => $this->request])); + } else { + // validation passes + $website = new Website(); + $website->name = $params['name']; + $website->link = $params['link']; + $website->xpath = $params['xpath']; + $website->save(); + + return new RedirectResponse(url('/websites')); + } + } else { + return new RedirectResponse(lastUrl('/')); + } + } + + /** + * Update page + * + * @return Response + */ + public function update($id) + { + $website = Website::find($id)->first(); + return new Response($this->view->render('websites/update', ['website' => $website])); + } + + /** + * POST Update page + */ + public function updatePost($id) + { + if(is_csrf_token()){ + $website = Website::find($id)->first(); + $params = $this->request->request->all(); + + $validator = new Validator; + $validator->addValidator('unique', new UniqueRule()); + + $this->rules['link'] = 'required|unique:websites,link,' . $website->link; + + // make it + $validation = $validator->make($params, $this->rules); + + // then validate + $validation->validate(); + + if ($validation->fails()) { + // handling errors + $errors = $validation->errors(); + return new Response($this->view->render('websites/update', ['errors' => $errors, 'website' => $website])); + } else { + // validation passes + $website->name = $params['name']; + $website->link = $params['link']; + $website->xpath = $params['xpath']; + $website->save(); + + return new RedirectResponse($params['previous']); + } + } else { + return new RedirectResponse(lastUrl('/')); + } + } + + /** + * POST Delete + */ + public function delete($id) + { + if(is_csrf_token()){ + $website = Website::find($id)->first(); + if($website->cookies()->count() > 0) { + return new RedirectResponse(lastUrl('/')); + } + $website = Website::destroy($id); + } + return new RedirectResponse(lastUrl('/')); + } +} diff --git a/core/app/Models/User.php b/core/app/Models/User.php new file mode 100644 index 0000000..79cb48f --- /dev/null +++ b/core/app/Models/User.php @@ -0,0 +1,11 @@ +hasMany('App\Models\Cookie', 'websites_id', 'id'); + } +} \ No newline at end of file diff --git a/core/app/Validation/UniqueRule.php b/core/app/Validation/UniqueRule.php new file mode 100644 index 0000000..f0ef014 --- /dev/null +++ b/core/app/Validation/UniqueRule.php @@ -0,0 +1,41 @@ +pdo = Capsule::connection()->getPdo(); + } + + public function check($value) + { + // make sure required parameters exists + $this->requireParameters(['table', 'column']); + + // getting parameters + $column = $this->parameter('column'); + $table = $this->parameter('table'); + $except = $this->parameter('except'); + + if ($except and $except == $value) { + return true; + } + + // do query + $stmt = $this->pdo->prepare("select count(*) as count from `{$table}` where `{$column}` = :value"); + $stmt->bindParam(':value', $value); + $stmt->execute(); + $data = $stmt->fetch(\PDO::FETCH_ASSOC); + + // true for valid, false for invalid + return intval($data['count']) === 0; + } +} \ No newline at end of file diff --git a/bootstrap/app.php b/core/bootstrap/app.php similarity index 59% rename from bootstrap/app.php rename to core/bootstrap/app.php index 2aa1656..4024f1c 100644 --- a/bootstrap/app.php +++ b/core/bootstrap/app.php @@ -7,15 +7,18 @@ use Symfony\Component\HttpFoundation\Response; use Whoops\Handler\PrettyPageHandler; use Whoops\Run; +use Illuminate\Database\Capsule\Manager as Capsule; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\RedirectResponse; -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../../vendor/autoload.php'; /* * Request instance (use this instead of $_GET, $_POST, etc). */ $request = Request::createFromGlobals(); - +$session = new Session(); /* * Container setup @@ -31,6 +34,10 @@ // http://container.thephpleague.com/auto-wiring new ReflectionContainer() ); + +$container + ->add('Symfony\Component\HttpFoundation\Session\Session'); + // Get Container App\Controllers\ErrorController $errorController = $container->get('App\Controllers\ErrorController'); @@ -38,13 +45,13 @@ * Dotenv initialization * https://github.com/vlucas/phpdotenv */ -if (file_exists(__DIR__ . '/../.env') !== true) { +if (file_exists(__DIR__ . '/../../.env') !== true) { Response::create('Missing .env file (please copy .env.example).', Response::HTTP_INTERNAL_SERVER_ERROR) ->prepare($request) ->send(); return; } -$dotenv = new Dotenv\Dotenv(__DIR__ . '/../'); +$dotenv = new Dotenv\Dotenv(__DIR__ . '/../../'); $dotenv->load(); @@ -74,18 +81,23 @@ function () use ($errorController) { /* * Database - * https://medoo.in/api/new */ -$container - ->add('Medoo\Medoo') - ->withArgument([ - 'database_type' => getenv('DB_CONNECTION') ? getenv('DB_CONNECTION') : 'mysql', - 'server' => getenv('DB_HOST') ? getenv('DB_HOST') : 'localhost', - 'port' => getenv('DB_PORT') ? getenv('DB_PORT') : 3306, - 'database_name' => getenv('DB_DATABASE') ? getenv('DB_DATABASE') : 'name', - 'username' => getenv('DB_USERNAME') ? getenv('DB_USERNAME') : 'your_username', - 'password' => getenv('DB_PASSWORD') ? getenv('DB_PASSWORD') : '' - ]); +$capsule = new Capsule; + $capsule->addConnection([ + 'driver' => getenv('DB_CONNECTION') ? getenv('DB_CONNECTION') : 'mysql', + 'host' => getenv('DB_HOST') ? getenv('DB_HOST') : 'localhost', + 'port' => getenv('DB_PORT') ? getenv('DB_PORT') : 3306, + 'database' => getenv('DB_DATABASE') ? getenv('DB_DATABASE') : 'name', + 'username' => getenv('DB_USERNAME') ? getenv('DB_USERNAME') : 'your_username', + 'password' => getenv('DB_PASSWORD') ? getenv('DB_PASSWORD') : '', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + ]); +// Setup the Eloquent ORM... +$capsule->setAsGlobal(); +$capsule->bootEloquent(); + /* * Routes @@ -132,13 +144,37 @@ function () use ($errorController) { // Resolves constructor dependencies using the container $controller = $container->get($fqcn); - // Generate a response by invoking the appropriate route method in the controller - $response = $controller->$routeMethod($routeParams); - if ($response instanceof Response) { - // Send the generated response back to the user - $response - ->prepare($request) - ->send(); + if(method_exists($controller, $routeMethod)){ + // Generate a response by invoking the appropriate route method in the controller + $response = $controller->$routeMethod($routeParams); + + $auth = isset($routeInfo[1][2]) ? $routeInfo[1][2] : NULL; + if($auth && $auth == AUTH){ + if(!$session->has('user')){ + $response = new RedirectResponse(url('/login')); + } + } + + $authAdmin = isset($routeInfo[1][3]) ? $routeInfo[1][3] : NULL; + if($authAdmin && $authAdmin == AUTH_ADMIN){ + if(!$session->get('user')->is_admin){ + $view = $container->get('League\Plates\Engine'); + $response = new Response($view->render('/errors/500', ['message' => 'Access Denied ;)'])); + } + } + + if($request->getPathInfo() == '/login' && $session->has('user')){ + $response = new RedirectResponse(url('/')); + } + + if ($response instanceof Response) { + // Send the generated response back to the user + $response + ->prepare($request) + ->send(); + } + } else { + $errorController->page404(); } break; default: diff --git a/core/helpers.php b/core/helpers.php new file mode 100644 index 0000000..dfe12c0 --- /dev/null +++ b/core/helpers.php @@ -0,0 +1,89 @@ +has($key); +} + +function lastUrl($defaultUrl) +{ + $request = Request::createFromGlobals(); + if ($request->request->has('previous')) { + return $request->request->get('previous'); + } + return $request->headers->get('referer') ? $request->headers->get('referer') : url($defaultUrl); +} + +function request() +{ + return Request::createFromGlobals(); +} + +/** + * CSRF + */ +function csrf_token() +{ + $session = new Session(); + if(!$session->has('csrf_token')){ + $session->set('csrf_token', md5(openssl_random_pseudo_bytes(32))); + } + return $session->get('csrf_token'); +} + +function is_csrf_token() +{ + $session = new Session(); + $request = Request::createFromGlobals(); + if($request->request->get('csrf_token') === $session->get('csrf_token')){ + $session->remove('csrf_token'); + return TRUE; + }else{ + return FALSE; + } +} +/** + * ./ CSRF + */ + +function auth() +{ + $session = new Session(); + if($session->has('user')){ + return $session->get('user'); + } + return false; +} + +function is_admin() +{ + $session = new Session(); + if($session->has('user') && $session->get('user')->is_admin){ + return true; + } + return false; +} \ No newline at end of file diff --git a/core/routes.php b/core/routes.php new file mode 100644 index 0000000..e080f55 --- /dev/null +++ b/core/routes.php @@ -0,0 +1,27 @@ +layout('layouts/app', ['title' => 'Dashboard']) ?> + + +
+

+ Dashboard + Control panel +

+ +
+ + +
+ + +
+
+ +
+
+

150

+ +

New Orders

+
+
+ +
+ More info +
+
+ +
+ +
+
+

53%

+ +

Bounce Rate

+
+
+ +
+ More info +
+
+ +
+ +
+
+

44

+ +

User Registrations

+
+
+ +
+ More info +
+
+ +
+ +
+
+

65

+ +

Unique Visitors

+
+
+ +
+ More info +
+
+ +
+ +
+ \ No newline at end of file diff --git a/views/layouts/app.php b/core/views/layouts/app.php similarity index 94% rename from views/layouts/app.php rename to core/views/layouts/app.php index 780d9cc..45e51aa 100644 --- a/views/layouts/app.php +++ b/core/views/layouts/app.php @@ -13,6 +13,7 @@ + section('CSS')?> + +section('JS')?> + + + diff --git a/views/layouts/auth.php b/core/views/layouts/auth.php similarity index 100% rename from views/layouts/auth.php rename to core/views/layouts/auth.php diff --git a/views/layouts/footer.php b/core/views/layouts/footer.php similarity index 100% rename from views/layouts/footer.php rename to core/views/layouts/footer.php diff --git a/views/layouts/navigation.php b/core/views/layouts/navigation.php similarity index 62% rename from views/layouts/navigation.php rename to core/views/layouts/navigation.php index a04563f..09ff35e 100644 --- a/views/layouts/navigation.php +++ b/core/views/layouts/navigation.php @@ -4,10 +4,10 @@
- User Image + User Image
-

Alexander Pierce

+

name : 'Alexander Pierce' ?>

Online
@@ -25,14 +25,24 @@ diff --git a/views/layouts/topnavbar.php b/core/views/layouts/topnavbar.php similarity index 90% rename from views/layouts/topnavbar.php rename to core/views/layouts/topnavbar.php index 13aba3b..2d49378 100644 --- a/views/layouts/topnavbar.php +++ b/core/views/layouts/topnavbar.php @@ -105,7 +105,7 @@