Model View Controller (MVC) design pattern for simple web applications.

Maintainers

Details

github.com/fabiodoppio/mvc

Source

Installs: 145

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Language:Smarty

1.52 2023-11-11 19:59 UTC

This package is auto-updated.

Last update: 2024-04-16 17:50:07 UTC


README

Model View Controller (MVC) design pattern for simple web applications.

Features

  • Default Pages for Home, Login, Signup, Recovery, Verification, Account and 404-Errors: Supports simple customizations through template files (.tpl) similar to Smarty.

  • Caching-Engine: Pages are automatically cached for improved performance, reducing server load by serving cached content when appropriate.

  • User Roles: Supports the implementation of user roles, define and manage different access levels and permissions for users.

  • Account Recovery: Users can recover their accounts through a user-friendly recovery process, they can regain access to their accounts in case of forgotten passwords or other issues.

  • Account Verification: Includes a built-in function to verify Accounts via E-Mail, enhancing security and trustworthiness in user registration.

  • Security Mechanisms: The package implements modern security measures to protect against potential attacks. This includes cooldown periods for repeated incorrect or unauthorized inputs and the verification of action tokens to prevent malicious actions.

  • Multi Language Support

  • More Features soon..

Installation

Official installation method is via composer and its packagist package fabiodoppio/mvc.

$ composer require fabiodoppio/mvc

..or just copy the example directory and run:

$ composer update

SQL-Statements for your Database:

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00"; CREATE TABLE `app_accounts`( `id` int UNSIGNED NOT NULL, `username` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `email` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `password` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `token` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `role` int UNSIGNED NOT NULL, `registered` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `lastaction` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; INSERT INTO `app_accounts` (`id`, `username`, `email`, `password`, `token`, `role`, `registered`, `lastaction`) VALUES (1000, 'admin', 'someone@example.com', '$2y$10$mF/1IeSTLohx/J35LYnEoueV50p3g9EOgnfADE0E7seJw127fHzY2', 'deP5E5KznHsLl0TMeLyvbndNg7KEky6W', 8, '2023-11-29 00:00:00', '2023-11-29 00:00:00'); CREATE TABLE `app_accounts_meta` ( `id` int UNSIGNED NOT NULL, `name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; CREATE TABLE `app_accounts_watchlist` ( `id` int UNSIGNED NOT NULL, `request` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `detected` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ALTER TABLE `app_accounts` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `username` (`username`), ADD UNIQUE KEY `email` (`email`); ALTER TABLE `app_accounts_meta` ADD PRIMARY KEY (`id`,`name`); ALTER TABLE `app_accounts_watchlist` ADD PRIMARY KEY (`id`,`detected`); ALTER TABLE `app_accounts` MODIFY `id` int UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1001; ALTER TABLE `app_accounts_meta` ADD CONSTRAINT `app_accounts_meta_ibfk_1` FOREIGN KEY (`id`) REFERENCES `app_accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE `app_accounts_watchlist` ADD CONSTRAINT `app_accounts_watchlist_ibfk_1` FOREIGN KEY (`id`) REFERENCES `app_accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; COMMIT;

Your .htaccess schould look like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^index\.php$ - [L]
    RewriteRule ^(.*)/$ /$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php [NC,QSA,L]
</IfModule>

Usage

The simplest usage to create an App would be as follows in your index.php:

<?php

require_once __DIR__.'/app/vendor/autoload.php';

MVC\App::init([
    "APP_URL"           => "https://",              // [REQUIRED] url to your app, no trailing slash
    #"APP_NAME"         => "My App",                // [OPTIONAL] name of your app
    #"APP_TITLE"        => "",                      // [OPTIONAL] title of your start page
    #"APP_AUTHOR"       => "",                      // [OPTIONAL] author of your app
    #"APP_DESCRIPTION"  => "",                      // [OPTIONAL] description of your app
    #"APP_LANGUAGE"     => "en_EN.utf8",            // [OPTIONAL] your prefered (server-)language
    #"APP_DEBUG"        => false,                   // [OPTIONAL] de/activates debug mode
    #"APP_LOGIN"        => true,                    // [OPTIONAL] de/activates login (except admins)
    #"APP_SIGNUP"       => false,                   // [OPTIONAL] de/activates signup
    #"CRON_ACTIVE"      => false,                   // [OPTIONAL] de/activates cronjob
    #"APP_MAINTENANCE"  => false,                   // [OPTIONAL] de/activates maintenance mode (except admins)
    #"APP_BADWORDS"     => [],                      // [OPTIONAL] forbidden words for usernames or messages
    #"APP_PAGES"        => [],                      // [OPTIONAL] urls to custom pages
   
    "SALT_COOKIE"       => "",                      // [REQUIRED] randomized hash for security reasons
    "SALT_TOKEN"        => "",                      // [REQUIRED] randomized hash for security reasons
    "SALT_CACHE"        => "",                      // [REQUIRED] randomized hash for security reasons
    "CRON_AUTH"         => "",                      // [REQUIRED] randomized hash for security reasons
    
    "DB_HOST"           => "",                      // [OPTIONAL] hostname to your mysql server
    "DB_USERNAME"       => "",                      // [OPTIONAL] username to your mysql server
    "DB_PASSWORD"       => "",                      // [OPTIONAL] password to your mysql server
    "DB_DATABASE"       => "",                      // [OPTIONAL] database to your mysql server

    "MAIL_HOST"         => "",                      // [OPTIONAL] hostname to your mail server
    "MAIL_SENDER"       => "",                      // [OPTIONAL] sender email address for system emails
    "MAIL_RECEIVER"     => "",                      // [OPTIONAL] receiver email address for contact form
    "MAIL_USERNAME"     => "",                      // [OPTIONAL] username to your mail server
    "MAIL_PASSWORD"     => "",                      // [OPTIONAL] password to your mail server
    #"MAIL_ENCRYPT"     => "ssl",                   // [OPTIONAL] ssl or tsl for encryption
    #"MAIL_PORT"        => "465,                    // [OPTIONAL] port to your mail server

    "DIR_ROOT"          => "/var/www"               // [REQUIRED] path to your root directory, no trailing slash
    #"DIR_ASSETS"       => "/app/assets",           // [OPTIONAL] path to your asset files, such as styles and scripts
    #"DIR_CLASSES"      => "/app/classes",          // [OPTIONAL] path to your custom or extended classes
    #"DIR_FONTS"        => "/app/assets/fonts",     // [OPTIONAL] path to your fonts
    #"DIR_SCRIPTS"      => "/app/assets/scripts",   // [OPTIONAL] path to your .js scripts
    #"DIR_STYLES"       => "/app/assets/styles",    // [OPTIONAL] path to your .css styles
    #"DIR_LOCALE"       => "/app/locale",           // [OPTIONAL] path to your locale .mo/.po files
    #"DIR_VENDOR"       => "/app/vendor",           // [OPTIONAL] path to your third-party libraries
    #"DIR_VIEWS"        => "/app/views",            // [OPTIONAL] path to your template files
    #"DIR_CACHE"        => "/app/cache",            // [OPTIONAL] path to your cache files
    #"DIR_MEDIA"        => "/app/media"             // [OPTIONAL] path to your media files
]);

?>

You can now log in at https://yourdomain/login

Username: admin Password: admin123

Don't forget to change your username and password!

Detailed documentation will coming soon..