diff --git a/README.md b/README.md deleted file mode 100644 index 3c025b9..0000000 --- a/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# PHP MVC framework -Minimalistic custom framework created for educational purposes. - - - -## The framework is not well tested on production. If you use it on production you use it on your own risk. -**Related core package**: https://github.com/thecodeholic/tc-php-mvc-core - ----- -## Installation - -1. Download the archive or clone the project using git -2. Create database schema -3. Create `.env` file from `.env.example` file and adjust database parameters (including schema name) -4. Run `composer install` -5. Run migrations by executing `php migrations.php` from the project root directory -6. Go to the `public` folder -7. Start php server by running command `php -S 127.0.0.1:8080` -8. Open in browser http://127.0.0.1:8080 - ------- -## Installation using docker -Make sure you have docker installed. To see how you can install docker on Windows [click here](https://youtu.be/2ezNqqaSjq8).
-Make sure `docker` and `docker-compose` commands are available in command line. - -1. Clone the project using git -1. Copy `.env.example` into `.env` (Don't need to change anything for local development) -1. Navigate to the project root directory and run `docker-compose up -d` -1. Install dependencies - `docker-compose exec app composer install` -1. Run migrations - `docker-compose exec app php migrations.php` -8. Open in browser http://127.0.0.1:8080 - -> The project was created along with Youtube Video Series "[Build PHP MVC Framework](https://www.youtube.com/playlist?list=PLLQuc_7jk__Uk_QnJMPndbdKECcTEwTA1)". -> I appreaciate if you share it. diff --git a/controllers/AboutController.php b/controllers/AboutController.php index b746311..a1fca6c 100644 --- a/controllers/AboutController.php +++ b/controllers/AboutController.php @@ -1,9 +1,4 @@ * @package app\controllers */ class AboutController extends Controller diff --git a/controllers/SiteController.php b/controllers/SiteController.php index fdb79b4..b35a849 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -1,9 +1,4 @@ * @package app\controllers */ class SiteController extends Controller @@ -29,18 +23,10 @@ public function __construct() $this->registerMiddleware(new AuthMiddleware(['profile'])); } - public function home() - { - return $this->render('home', [ - 'name' => 'TheCodeholic' - ]); - } public function login(Request $request) { - echo '
';
-        var_dump($request->getBody(), $request->getRouteParam('id'));
-        echo '
'; + $loginForm = new LoginForm(); if ($request->getMethod() === 'post') { $loginForm->loadData($request->getBody()); @@ -55,44 +41,10 @@ public function login(Request $request) ]); } - public function register(Request $request) - { - $registerModel = new User(); - if ($request->getMethod() === 'post') { - $registerModel->loadData($request->getBody()); - if ($registerModel->validate() && $registerModel->save()) { - Application::$app->session->setFlash('success', 'Thanks for registering'); - Application::$app->response->redirect('/'); - return 'Show success page'; - } - - } - $this->setLayout('auth'); - return $this->render('register', [ - 'model' => $registerModel - ]); - } - public function logout(Request $request, Response $response) { Application::$app->logout(); $response->redirect('/'); } - public function contact() - { - return $this->render('contact'); - } - - public function profile() - { - return $this->render('profile'); - } - - public function profileWithId(Request $request) - { - echo '
';
-        var_dump($request->getBody());
-        echo '
'; - } } diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 8f1a64c..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: "3.7" - -services: - app: - build: ./docker - image: thecodeholic/php_mvc - ports: - - "8080:80" - volumes: - # Mount source-code for development - - ./:/var/www - extra_hosts: - - host.docker.internal:host-gateway - - db: - image: mysql:8 - ports: - - "3307:3306" - volumes: - - mysql-data:/var/lib/mysql - - ./docker/mysql-config.cnf:/etc/mysql/conf.d/config.cnf - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: php_mvc - MYSQL_USER: php_mvc - MYSQL_PASSWORD: php_mvc - -volumes: - mysql-data: \ No newline at end of file diff --git a/migrations.php b/migrations.php index ab7cf2f..e45d0cb 100644 --- a/migrations.php +++ b/migrations.php @@ -1,9 +1,4 @@ * @package app\models */ class LoginForm extends Model diff --git a/models/User.php b/models/User.php index 2cc6383..d0376ce 100644 --- a/models/User.php +++ b/models/User.php @@ -1,9 +1,4 @@ * @package app\models */ class User extends UserModel diff --git a/public/index.php b/public/index.php index 8572ddf..5fcd761 100644 --- a/public/index.php +++ b/public/index.php @@ -1,9 +1,4 @@ load(); $config = [ @@ -19,26 +15,26 @@ 'dsn' => $_ENV['DB_DSN'], 'user' => $_ENV['DB_USER'], 'password' => $_ENV['DB_PASSWORD'], - ] + ], + ]; $app = new Application(dirname(__DIR__), $config); -$app->on(Application::EVENT_BEFORE_REQUEST, function(){ +$app->on(Application::EVENT_BEFORE_REQUEST, function () { // echo "Before request from second installation"; }); +$app->router->get('/', function () { + header('Location: /login'); +}); -$app->router->get('/', [SiteController::class, 'home']); -$app->router->get('/register', [SiteController::class, 'register']); -$app->router->post('/register', [SiteController::class, 'register']); $app->router->get('/login', [SiteController::class, 'login']); +$app->router->get('/login', [SiteController::class, 'login']); +$app->router->get('/admin', [SiteController::class, 'ad']); $app->router->get('/login/{id}', [SiteController::class, 'login']); $app->router->post('/login', [SiteController::class, 'login']); $app->router->get('/logout', [SiteController::class, 'logout']); -$app->router->get('/contact', [SiteController::class, 'contact']); -$app->router->get('/about', [AboutController::class, 'index']); -$app->router->get('/profile', [SiteController::class, 'profile']); -$app->router->get('/profile/{id:\d+}/{username}', [SiteController::class, 'login']); +//var_dump(Application::$app->user); // /profile/{id} // /profile/13 // \/profile\/\w+ diff --git a/views/_error.php b/views/_error.php index 1999856..67c0857 100644 --- a/views/_error.php +++ b/views/_error.php @@ -1,8 +1,5 @@ diff --git a/views/about.php b/views/about.php deleted file mode 100644 index 35f8d8b..0000000 --- a/views/about.php +++ /dev/null @@ -1 +0,0 @@ -

About me

\ No newline at end of file diff --git a/views/contact.php b/views/contact.php deleted file mode 100644 index b865df0..0000000 --- a/views/contact.php +++ /dev/null @@ -1 +0,0 @@ -

Contact page

\ No newline at end of file diff --git a/views/home.php b/views/home.php deleted file mode 100644 index 1b35e5d..0000000 --- a/views/home.php +++ /dev/null @@ -1 +0,0 @@ -

Welcome

\ No newline at end of file diff --git a/views/layouts/auth.php b/views/layouts/auth.php index 7f31069..c1f3755 100644 --- a/views/layouts/auth.php +++ b/views/layouts/auth.php @@ -4,13 +4,9 @@ - - - - - - Hello, world! + + + Login - <?php echo $_ENV['APP_NAME'] ?> @@ -19,15 +15,6 @@ - - - - + \ No newline at end of file diff --git a/views/layouts/fonts.php b/views/layouts/fonts.php new file mode 100644 index 0000000..ec28f8d --- /dev/null +++ b/views/layouts/fonts.php @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/views/layouts/main.php b/views/layouts/main.php index 571f8d0..3843706 100644 --- a/views/layouts/main.php +++ b/views/layouts/main.php @@ -6,10 +6,9 @@ - + + - <?php echo $this->title ?> @@ -70,15 +69,7 @@ - - - - + + \ No newline at end of file diff --git a/views/login.php b/views/login.php index 8f63e11..63b315d 100644 --- a/views/login.php +++ b/views/login.php @@ -1,15 +1,97 @@ - + body { + background-color: #F3F4F6; + display: flex; + justify-content: center; + align-content: center; + } -/** @var $model \app\models\LoginForm */ + .login-form { + width: 100%; + max-width: 400px; + margin: 100px auto; + } -use thecodeholic\phpmvc\form\Form; + .login-form .title { + text-align: center; + font-size: 30px; + font-weight: 400; + margin-bottom: 30px; + color: #AB5E25; + } -?> + .login-form .form-card { + background-color: #fff; + padding: 30px; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + } -

Login

+ .login-form .form-group { + margin-bottom: 20px; + } - - field($model, 'email') ?> - field($model, 'password')->passwordField() ?> - - \ No newline at end of file + .login-form .form-group label { + font-family: 'Tajawal'; + font-style: normal; + font-weight: 700; + font-size: 16px; + line-height: 36px; + color: #777777; + + } + + .login-form .form-group input { + width: 100%; + height: 40px; + border: 1px solid #ddd; + border-radius: 5px; + padding: 0 10px; + font-size: 16px; + font-weight: 500; + } + + .login-form .btn-login { + width: 40%; + height: 40px; + color: #000; + font-size: 16px; + font-weight: 500; + cursor: pointer; + background: #F2F2F2; + border: 1px solid rgba(0, 0, 0, 0.28); + border-radius: 8px; + } + + .login-form .btn-login:hover { + background-color: #fcfcfc; + opacity: 0.8; + } + + .login-form .form-group .btn-login { + margin-top: 20px; + } + a{ + color: #4596E1; + text-decoration: none; + } + +
+

Shop Sens

+
+
+
+ + +
+
+ + +
+
+ + Reset Your Password ? +
+
+
+
\ No newline at end of file diff --git a/views/profile.php b/views/profile.php deleted file mode 100644 index e58576b..0000000 --- a/views/profile.php +++ /dev/null @@ -1,7 +0,0 @@ -title = 'Profile'; -?> - -

Profile page

\ No newline at end of file diff --git a/views/register.php b/views/register.php deleted file mode 100644 index e9722a5..0000000 --- a/views/register.php +++ /dev/null @@ -1,24 +0,0 @@ - - -

Register

- - -
-
- field($model, 'firstname') ?> -
-
- field($model, 'lastname') ?> -
-
- field($model, 'email') ?> - field($model, 'password')->passwordField() ?> - field($model, 'passwordConfirm')->passwordField() ?> - - \ No newline at end of file