From da38e7daf0e0b7f80cb7e1c0f8aa8ad05a6a8568 Mon Sep 17 00:00:00 2001 From: Gabriel Oliveira Date: Fri, 26 Jul 2024 10:41:23 -0300 Subject: [PATCH] Standard formatting --- app/commands/Quote.php | 74 ++-- app/config/Config.php | 324 +++++++++--------- app/config/Routes.php | 21 +- app/controllers/BaseController.php | 40 +-- app/controllers/Error.php | 134 ++++---- app/controllers/Main.php | 59 ++-- app/jobs/SendMail.php | 44 +-- app/languages/en.php | 46 ++- app/middlewares/Authenticate.php | 83 ++--- app/middlewares/RateLimiter.php | 123 +++---- app/middlewares/ValidateCsrfToken.php | 83 ++--- .../m2021_07_05_210000_CreateUsersTable.php | 76 ++-- .../m2021_07_05_220000_PopulateUsersTable.php | 89 ++--- app/models/Users.php | 212 ++++++------ app/public/assets/css/glowie.css | 2 +- app/public/index.php | 39 +-- app/views/helpers/Helpers.php | 48 +-- app/views/layouts/default.phtml | 29 +- firefly | 43 ++- 19 files changed, 792 insertions(+), 777 deletions(-) diff --git a/app/commands/Quote.php b/app/commands/Quote.php index 70951d0..4c8a3cf 100644 --- a/app/commands/Quote.php +++ b/app/commands/Quote.php @@ -1,44 +1,44 @@ random(); +/** + * Inspirational CLI command for Glowie application. + * @category Command + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class Quote extends Command +{ - // Prints the quote in the console - $this->info($quote); - } + /** + * The command script. + */ + public function run() + { + // Gets a random quote + $quote = (new Collection([ + '"Computers are fast; programmers keep it slow."', + '"Programming can be fun, and so can cryptography; however, they should not be combined."', + '"When we had no computers, we had no programming problems either."', + '"There is no Ctrl-Z in life."', + '"Whitespace is never white."', + '"When all else fails... reboot."', + '"The computer was born to solve problems that did not exist before."', + '"There\'s no place like 127.0.0.1."', + '"It works on my machine."', + '"A good programmer is someone who always looks both ways before crossing a one-way street."', + '"Software and cathedrals are much the same — first we build them, then we pray."', + '"It\'s not a bug – it\'s an undocumented feature."' + ]))->random(); + // Prints the quote in the console + $this->info($quote); } - -?> \ No newline at end of file +} diff --git a/app/config/Config.php b/app/config/Config.php index 1f4d36d..0105ef0 100644 --- a/app/config/Config.php +++ b/app/config/Config.php @@ -1,234 +1,234 @@ Env::get('APP_ENV', 'development'), + // Current environment name + 'env' => Env::get('APP_ENV', 'development'), - // Application maintenance mode - 'maintenance' => [ + // Application maintenance mode + 'maintenance' => [ - // Enable maintenance mode - 'enabled' => filter_var( - Env::get('APP_MAINTENANCE', false), - FILTER_VALIDATE_BOOLEAN), + // Enable maintenance mode + 'enabled' => filter_var( + Env::get('APP_MAINTENANCE', false), + FILTER_VALIDATE_BOOLEAN + ), - // Maintenance mode bypass key - 'bypass_key' => Env::get('MAINTENANCE_KEY') + // Maintenance mode bypass key + 'bypass_key' => Env::get('MAINTENANCE_KEY') - ], + ], - // Skeltch templating engine - 'skeltch' => [ + // Skeltch templating engine + 'skeltch' => [ - // Enable Skeltch compiler - 'enabled' => true, + // Enable Skeltch compiler + 'enabled' => true, - // Enable views caching - 'cache' => true, + // Enable views caching + 'cache' => true, - // Cache files location - 'path' => Util::location('storage/cache') + // Cache files location + 'path' => Util::location('storage/cache') - ], + ], - // Application error reporting - 'error_reporting' => [ + // Application error reporting + 'error_reporting' => [ - // Error reporting level - 'level' => filter_var( - Env::get('APP_DEBUG', true), - FILTER_VALIDATE_BOOLEAN) ? E_ALL : 0, + // Error reporting level + 'level' => filter_var( + Env::get('APP_DEBUG', true), + FILTER_VALIDATE_BOOLEAN + ) ? E_ALL : 0, - // Enable error logging - 'logging' => true, + // Enable error logging + 'logging' => true, - // Error log file location - 'file' => Util::location('storage/error.log') + // Error log file location + 'file' => Util::location('storage/error.log') - ], + ], - // Application session management - 'session' => [ + // Application session management + 'session' => [ - // Session cookie name - 'name' => 'app_session', + // Session cookie name + 'name' => 'app_session', - // Unused session lifetime - 'lifetime' => 120, + // Unused session lifetime + 'lifetime' => 120, - // Number of requests when to run the garbage collector - 'gc_cleaning' => 50, + // Number of requests when to run the garbage collector + 'gc_cleaning' => 50, - // Session files location - 'path' => Util::location('storage/session'), + // Session files location + 'path' => Util::location('storage/session'), - // Allow session usage only in secure connections (https) - 'secure' => false, + // Allow session usage only in secure connections (https) + 'secure' => false, - // Restrict session access to the HTTP protocol only - 'restrict' => true + // Restrict session access to the HTTP protocol only + 'restrict' => true - ], + ], - // Application cookies management - 'cookies' => [ + // Application cookies management + 'cookies' => [ - // Allow cookies usage only through secure connections (https) - 'secure' => false, + // Allow cookies usage only through secure connections (https) + 'secure' => false, - // Restrict cookies access to the HTTP protocol only - 'restrict' => true + // Restrict cookies access to the HTTP protocol only + 'restrict' => true - ], + ], - // Application secret keys - 'secret' => [ + // Application secret keys + 'secret' => [ - // Key used in encrypting functions - 'app_key' => Env::get('APP_KEY'), + // Key used in encrypting functions + 'app_key' => Env::get('APP_KEY'), - // Token used in encrypting functions - 'app_token' => Env::get('APP_TOKEN') + // Token used in encrypting functions + 'app_token' => Env::get('APP_TOKEN') - ], + ], - // Application database connection settings - 'database' => [ + // Application database connection settings + 'database' => [ - // Default connection - 'default' => [ - 'host' => Env::get('DB_HOST', 'localhost'), - 'username' => Env::get('DB_USERNAME', 'root'), - 'password' => Env::get('DB_PASSWORD', ''), - 'db' => Env::get('DB_DATABASE', 'glowie'), - 'port' => Env::get('DB_PORT', 3306), - 'charset' => 'utf8', - 'strict' => false - ] - - ], + // Default connection + 'default' => [ + 'host' => Env::get('DB_HOST', 'localhost'), + 'username' => Env::get('DB_USERNAME', 'root'), + 'password' => Env::get('DB_PASSWORD', ''), + 'db' => Env::get('DB_DATABASE', 'glowie'), + 'port' => Env::get('DB_PORT', 3306), + 'charset' => 'utf8', + 'strict' => false + ] - // Authentication settings - 'auth' => [ + ], - // Default auth guard - 'default' => [ - // Users model - 'model' => \Glowie\Models\Users::class, + // Authentication settings + 'auth' => [ - // User field name - 'user_field' => 'email', + // Default auth guard + 'default' => [ + // Users model + 'model' => \Glowie\Models\Users::class, - // Password field name - 'password_field' => 'password' - ] + // User field name + 'user_field' => 'email', - ], + // Password field name + 'password_field' => 'password' + ] - // Migrations settings - 'migrations' => [ + ], - // Migrations history table name - 'table' => 'migrations' + // Migrations settings + 'migrations' => [ - ], + // Migrations history table name + 'table' => 'migrations' - // Queue settings - 'queue' => [ + ], - // Queue jobs table name - 'table' => 'queue', + // Queue settings + 'queue' => [ - // Max attempts to retry failed jobs - 'max_attempts' => 3 + // Queue jobs table name + 'table' => 'queue', - ], + // Max attempts to retry failed jobs + 'max_attempts' => 3 - // Cache settings - 'cache' => [ + ], - // Cache file path - 'path' => Util::location('storage/cache/cache.db') + // Cache settings + 'cache' => [ - ], + // Cache file path + 'path' => Util::location('storage/cache/cache.db') - // Cross-Origin Resource Sharing (CORS) settings - 'cors' => [ + ], - // Enable CORS headers - 'enabled' => true, + // Cross-Origin Resource Sharing (CORS) settings + 'cors' => [ - // List of allowed methods (use * for all) - 'allowed_methods' => ['*'], + // Enable CORS headers + 'enabled' => true, - // List of allowed origins (use * for all) - 'allowed_origins' => ['*'], + // List of allowed methods (use * for all) + 'allowed_methods' => ['*'], - // List of allowed headers (use * for all) - 'allowed_headers' => ['*'], + // List of allowed origins (use * for all) + 'allowed_origins' => ['*'], - // List of exposed headers - 'exposed_headers' => [], + // List of allowed headers (use * for all) + 'allowed_headers' => ['*'], - // Preflight request cache time - 'max_age' => 0, + // List of exposed headers + 'exposed_headers' => [], - // Allow credentials to be exposed - 'allow_credentials' => false + // Preflight request cache time + 'max_age' => 0, - ], + // Allow credentials to be exposed + 'allow_credentials' => false - // Application plugins - 'plugins' => [], + ], - // Firefly Sandbox settings - 'sandbox' => [ + // Application plugins + 'plugins' => [], - // Sandbox class alias list - 'alias' => [ - 'Factory' => \Glowie\Core\Database\Factory::class, - 'Kraken' => \Glowie\Core\Database\Kraken::class, - 'Model' => \Glowie\Core\Database\Model::class, - 'Skeleton' => \Glowie\Core\Database\Skeleton::class, - 'Rails' => \Glowie\Core\Http\Rails::class, - 'Queue' => \Glowie\Core\Queue\Queue::class, - 'Cache' => \Glowie\Core\Tools\Cache::class, - 'Crawler' => \Glowie\Core\Tools\Crawler::class, - 'Mailer' => \Glowie\Core\Tools\Mailer::class, - 'Validator' => \Glowie\Core\Tools\Validator::class, - 'Collection' => \Glowie\Core\Collection::class, - 'Element' => \Glowie\Core\Element::class - ] + // Firefly Sandbox settings + 'sandbox' => [ - ], + // Sandbox class alias list + 'alias' => [ + 'Factory' => \Glowie\Core\Database\Factory::class, + 'Kraken' => \Glowie\Core\Database\Kraken::class, + 'Model' => \Glowie\Core\Database\Model::class, + 'Skeleton' => \Glowie\Core\Database\Skeleton::class, + 'Rails' => \Glowie\Core\Http\Rails::class, + 'Queue' => \Glowie\Core\Queue\Queue::class, + 'Cache' => \Glowie\Core\Tools\Cache::class, + 'Crawler' => \Glowie\Core\Tools\Crawler::class, + 'Mailer' => \Glowie\Core\Tools\Mailer::class, + 'Validator' => \Glowie\Core\Tools\Validator::class, + 'Collection' => \Glowie\Core\Collection::class, + 'Element' => \Glowie\Core\Element::class + ] - // Application miscellaneous settings - 'other' => [ + ], - // Application URL (for CLI route mocking only) - 'url' => Env::get('APP_URL', 'http://localhost'), + // Application miscellaneous settings + 'other' => [ - // Default language - 'language' => 'en', + // Application URL (for CLI route mocking only) + 'url' => Env::get('APP_URL', 'http://localhost'), - // Default timezone - 'timezone' => 'America/Sao_Paulo' + // Default language + 'language' => 'en', - ] + // Default timezone + 'timezone' => 'America/Sao_Paulo' - ]; + ] -?> \ No newline at end of file +]; diff --git a/app/config/Routes.php b/app/config/Routes.php index 82bd8a3..a8b5256 100644 --- a/app/config/Routes.php +++ b/app/config/Routes.php @@ -1,15 +1,14 @@ \ No newline at end of file +Rails::addRoute('/', Main::class, 'index'); diff --git a/app/controllers/BaseController.php b/app/controllers/BaseController.php index 0a6bf5c..7265d02 100644 --- a/app/controllers/BaseController.php +++ b/app/controllers/BaseController.php @@ -1,26 +1,26 @@ \ No newline at end of file +} diff --git a/app/controllers/Error.php b/app/controllers/Error.php index e4a74ec..3be52f0 100644 --- a/app/controllers/Error.php +++ b/app/controllers/Error.php @@ -1,75 +1,79 @@ renderLayout('default', 'error/error', [ - 'title' => 'Page Not Found', - 'code' => 404, - 'message' => Babel::get('errors.not_found') - ]); - } +/** + * Error controller for Glowie application. + * @category Controller + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class Error extends BaseController +{ - /** - * Handler for 403 Forbidden errors. - */ - public function forbidden(){ - // Renders 403 error page - $this->renderLayout('default', 'error/error', [ - 'title' => 'Access Forbidden', - 'code' => 403, - 'message' => Babel::get('errors.forbidden') - ]); - } + /** + * This method will be called before any other methods from this controller. + */ + public function init() + { + // Calls the BaseController init() method + if (is_callable([parent::class, 'init'])) parent::init(); + } - /** - * Handler for 405 Method Not Allowed errors. - */ - public function methodNotAllowed(){ - // Renders 405 error page - $this->renderLayout('default', 'error/error', [ - 'title' => 'Not Allowed', - 'code' => 405, - 'message' => Babel::get('errors.not_allowed') - ]); - } + /** + * Handler for 404 Not Found errors. + */ + public function notFound() + { + // Renders 404 error page + $this->renderLayout('default', 'error/error', [ + 'title' => 'Page Not Found', + 'code' => 404, + 'message' => Babel::get('errors.not_found') + ]); + } - /** - * Handler for 503 Service Unavailable errors. - */ - public function serviceUnavailable(){ - // Renders 503 error page - $this->renderLayout('default', 'error/error', [ - 'title' => 'Service Unavailable', - 'code' => 503, - 'message' => Babel::get('errors.service_unavailable') - ]); - } + /** + * Handler for 403 Forbidden errors. + */ + public function forbidden() + { + // Renders 403 error page + $this->renderLayout('default', 'error/error', [ + 'title' => 'Access Forbidden', + 'code' => 403, + 'message' => Babel::get('errors.forbidden') + ]); + } + /** + * Handler for 405 Method Not Allowed errors. + */ + public function methodNotAllowed() + { + // Renders 405 error page + $this->renderLayout('default', 'error/error', [ + 'title' => 'Not Allowed', + 'code' => 405, + 'message' => Babel::get('errors.not_allowed') + ]); } -?> \ No newline at end of file + /** + * Handler for 503 Service Unavailable errors. + */ + public function serviceUnavailable() + { + // Renders 503 error page + $this->renderLayout('default', 'error/error', [ + 'title' => 'Service Unavailable', + 'code' => 503, + 'message' => Babel::get('errors.service_unavailable') + ]); + } +} diff --git a/app/controllers/Main.php b/app/controllers/Main.php index 9e9a645..4e9a7ca 100644 --- a/app/controllers/Main.php +++ b/app/controllers/Main.php @@ -1,35 +1,36 @@ renderLayout('default', 'index', [ - 'title' => 'Welcome to Glowie!' - ]); - } +/** + * Main controller for Glowie application. + * @category Controller + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class Main extends BaseController +{ + /** + * This method will be called before any other methods from this controller. + */ + public function init() + { + // Calls the BaseController init() method + if (is_callable([parent::class, 'init'])) parent::init(); } -?> \ No newline at end of file + /** + * Index action. + */ + public function index() + { + // Renders the starting page + $this->renderLayout('default', 'index', [ + 'title' => 'Welcome to Glowie!' + ]); + } +} diff --git a/app/jobs/SendMail.php b/app/jobs/SendMail.php index 8312d15..89f4467 100644 --- a/app/jobs/SendMail.php +++ b/app/jobs/SendMail.php @@ -1,28 +1,28 @@ addTo($this->data->email); - $mail->send($this->data->subject, $this->data->message); - } +/** + * Send mail job for Glowie application. + * @category Queue + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + */ +class SendMail extends Job +{ + /** + * Runs the job. + */ + public function run() + { + $mail = new Mailer(); + $mail->addTo($this->data->email); + $mail->send($this->data->subject, $this->data->message); } - -?> \ No newline at end of file +} diff --git a/app/languages/en.php b/app/languages/en.php index 1774f36..3ae372d 100644 --- a/app/languages/en.php +++ b/app/languages/en.php @@ -1,35 +1,33 @@ [ + // Error messages + 'errors' => [ - // 403 error message - 'forbidden' => 'You are not allowed to access this page', + // 403 error message + 'forbidden' => 'You are not allowed to access this page', - // 404 error message - 'not_found' => 'The page you were looking for was not found', + // 404 error message + 'not_found' => 'The page you were looking for was not found', - // 405 error message - 'not_allowed' => 'The current method is not allowed', + // 405 error message + 'not_allowed' => 'The current method is not allowed', - // 429 error message - 'rate_limit' => 'Request limit reached, please wait', + // 429 error message + 'rate_limit' => 'Request limit reached, please wait', - // 503 error message - 'service_unavailable' => 'We will be back soon' + // 503 error message + 'service_unavailable' => 'We will be back soon' - ] + ] - ]; - -?> \ No newline at end of file +]; diff --git a/app/middlewares/Authenticate.php b/app/middlewares/Authenticate.php index ca41dad..bb49dc2 100644 --- a/app/middlewares/Authenticate.php +++ b/app/middlewares/Authenticate.php @@ -1,48 +1,49 @@ check(); - } - - /** - * Called if the middleware handler returns false. - */ - public function fail(){ - // Clear session data - (new Authenticator())->logout(); - - // Set HTTP 403 status code - $this->response->deny(); +use Glowie\Core\Http\Middleware; +use Glowie\Core\Tools\Authenticator; +use Babel; - // Renders 403 error page - $this->controller->renderLayout('default', 'error/error', [ - 'title' => 'Access Forbidden', - 'code' => 403, - 'message' => Babel::get('errors.forbidden') - ]); - } +/** + * Authentication middleware for Glowie application. + * @category Middleware + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class Authenticate extends Middleware +{ + /** + * The middleware handler. + * @return bool Should return true on success or false on fail. + */ + public function handle() + { + // Checks if user is authenticated + return (new Authenticator())->check(); } -?> \ No newline at end of file + /** + * Called if the middleware handler returns false. + */ + public function fail() + { + // Clear session data + (new Authenticator())->logout(); + + // Set HTTP 403 status code + $this->response->deny(); + + // Renders 403 error page + $this->controller->renderLayout('default', 'error/error', [ + 'title' => 'Access Forbidden', + 'code' => 403, + 'message' => Babel::get('errors.forbidden') + ]); + } +} diff --git a/app/middlewares/RateLimiter.php b/app/middlewares/RateLimiter.php index 35d9b28..799a24a 100644 --- a/app/middlewares/RateLimiter.php +++ b/app/middlewares/RateLimiter.php @@ -1,76 +1,77 @@ request->getIPAddress(); + /** + * The middleware handler. + * @return bool Should return true on success or false on fail. + */ + public function handle() + { + // Creates the cache instance + $cache = new Cache(); - // Gets the current number of attempts - $attempts = (int)$cache->get($key, 0); + // Sets the rate limiter key with the IP address and unique identifier + $key = 'glowie.ratelimiter_' . self::UNIQUE_ID . '_' . $this->request->getIPAddress(); - // Limits the attempts - if($attempts >= self::MAX_ATTEMPTS) return false; + // Gets the current number of attempts + $attempts = (int)$cache->get($key, 0); - // Sets the new number of attempts - $cache->set($key, $attempts + 1, self::TIME_LIMIT); - return true; - } + // Limits the attempts + if ($attempts >= self::MAX_ATTEMPTS) return false; - /** - * Called if the middleware handler returns false. - */ - public function fail(){ - // Set HTTP 429 status code - $this->response->rateLimit(); + // Sets the new number of attempts + $cache->set($key, $attempts + 1, self::TIME_LIMIT); + return true; + } - // Renders 429 error page - $this->controller->renderLayout('default', 'error/error', [ - 'title' => 'Too Many Requests', - 'code' => 429, - 'message' => Babel::get('errors.rate_limit') - ]); - } + /** + * Called if the middleware handler returns false. + */ + public function fail() + { + // Set HTTP 429 status code + $this->response->rateLimit(); + // Renders 429 error page + $this->controller->renderLayout('default', 'error/error', [ + 'title' => 'Too Many Requests', + 'code' => 429, + 'message' => Babel::get('errors.rate_limit') + ]); } - -?> \ No newline at end of file +} diff --git a/app/middlewares/ValidateCsrfToken.php b/app/middlewares/ValidateCsrfToken.php index 1f8ff0d..874d566 100644 --- a/app/middlewares/ValidateCsrfToken.php +++ b/app/middlewares/ValidateCsrfToken.php @@ -1,48 +1,49 @@ post->_token ?? $this->request->getHeader('X-CSRF-TOKEN'); - - // Validates the token - if(empty($token)) return false; - return $this->request->checkCsrfToken($token); - } - - /** - * Called if the middleware handler returns false. - */ - public function fail(){ - // Set HTTP 403 status code - $this->response->deny(); +use Glowie\Core\Http\Middleware; +use Babel; - // Renders 403 error page - $this->controller->renderLayout('default', 'error/error', [ - 'title' => 'Access Forbidden', - 'code' => 403, - 'message' => Babel::get('errors.forbidden') - ]); - } +/** + * CSRF token validation middleware for Glowie application. + * @category Middleware + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class ValidateCsrfToken extends Middleware +{ + /** + * The middleware handler. + * @return bool Should return true on success or false on fail. + */ + public function handle() + { + // Retrieves the token from POST field or header + $token = $this->post->_token ?? $this->request->getHeader('X-CSRF-TOKEN'); + + // Validates the token + if (empty($token)) return false; + return $this->request->checkCsrfToken($token); } -?> \ No newline at end of file + /** + * Called if the middleware handler returns false. + */ + public function fail() + { + // Set HTTP 403 status code + $this->response->deny(); + + // Renders 403 error page + $this->controller->renderLayout('default', 'error/error', [ + 'title' => 'Access Forbidden', + 'code' => 403, + 'message' => Babel::get('errors.forbidden') + ]); + } +} diff --git a/app/migrations/m2021_07_05_210000_CreateUsersTable.php b/app/migrations/m2021_07_05_210000_CreateUsersTable.php index b1a637b..a183b70 100644 --- a/app/migrations/m2021_07_05_210000_CreateUsersTable.php +++ b/app/migrations/m2021_07_05_210000_CreateUsersTable.php @@ -1,43 +1,47 @@ forge->table('users') - ->id() - ->createColumn('name', 'VARCHAR', 255) - ->createColumn('email', 'VARCHAR', 255) - ->createColumn('password', 'VARCHAR', 255) - ->createTimestamps() - ->createSoftDeletes() - ->ifNotExists() - ->create(); - } - - /** - * Rolls back the migration. - * @return bool Returns true on success or false on errors. - */ - public function rollback(){ - return $this->forge->table('users')->ifExists()->drop(); - } +/** + * Sample migration for Glowie application. + * @category Migration + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class m2021_07_05_210000_CreateUsersTable extends Migration +{ + /** + * Runs the migration. + * @return bool Returns true on success or false on errors. + */ + public function run() + { + return $this->forge->table('users') + ->id() + ->createColumn('name', Skeleton::TYPE_STRING, 255) + ->createColumn('email', Skeleton::TYPE_STRING, 255) + ->createColumn('password', Skeleton::TYPE_TEXT) + ->createTimestamps() + ->createSoftDeletes() + ->ifNotExists() + ->create(); } -?> \ No newline at end of file + /** + * Rolls back the migration. + * @return bool Returns true on success or false on errors. + */ + public function rollback() + { + return $this->forge->table('users') + ->ifExists() + ->drop(); + } +} diff --git a/app/migrations/m2021_07_05_220000_PopulateUsersTable.php b/app/migrations/m2021_07_05_220000_PopulateUsersTable.php index adb6f3c..0c4221f 100644 --- a/app/migrations/m2021_07_05_220000_PopulateUsersTable.php +++ b/app/migrations/m2021_07_05_220000_PopulateUsersTable.php @@ -1,51 +1,52 @@ db->table('users')->insert([ - [ - 'name' => 'Lorem Ipsum', - 'email' => 'lorem@ipsum.com', - 'password' => password_hash('123', PASSWORD_DEFAULT) - ], - [ - 'name' => 'Jane Doe', - 'email' => 'janedoe@gmail.com', - 'password' => password_hash('jane@2021', PASSWORD_DEFAULT) - ], - [ - 'name' => 'John Oliver', - 'email' => 'john_oliver@hotmail.com', - 'password' => password_hash('iloveburrito', PASSWORD_DEFAULT) - ] - ]); - } - - /** - * Rolls back the migration. - * @return bool Returns true on success or false on errors. - */ - public function rollback(){ - return $this->forge->table('users')->truncate(); - } +/** + * Sample migration for Glowie application. + * @category Migration + * @package glowieframework/glowie + * @author Glowie + * @copyright Copyright (c) Glowie + * @license MIT + * @link https://gabrielsilva.dev.br/glowie + */ +class m2021_07_05_220000_PopulateUsersTable extends Migration +{ + /** + * Runs the migration. + * @return bool Returns true on success or false on errors. + */ + public function run() + { + return $this->db->table('users')->insert([ + [ + 'name' => 'Lorem Ipsum', + 'email' => 'lorem@ipsum.com', + 'password' => password_hash('123', PASSWORD_DEFAULT) + ], + [ + 'name' => 'Jane Doe', + 'email' => 'janedoe@gmail.com', + 'password' => password_hash('jane@2021', PASSWORD_DEFAULT) + ], + [ + 'name' => 'John Oliver', + 'email' => 'john_oliver@hotmail.com', + 'password' => password_hash('iloveburrito', PASSWORD_DEFAULT) + ] + ]); } -?> \ No newline at end of file + /** + * Rolls back the migration. + * @return bool Returns true on success or false on errors. + */ + public function rollback() + { + return $this->forge->table('users')->truncate(); + } +} diff --git a/app/models/Users.php b/app/models/Users.php index 171221b..8992706 100644 --- a/app/models/Users.php +++ b/app/models/Users.php @@ -1,109 +1,113 @@ 'int', + 'created_at' => 'date', + 'updated_at' => 'date', + 'deleted_at' => 'date' + ]; + + /** + * Table fields data types to mutate. + * @var array + */ + protected $_mutators = []; + + /** + * Handle timestamp fields. + * @var bool + */ + protected $_timestamps = true; + + /** + * Timestamp fields date format. + * @var string + */ + protected $_dateFormat = 'Y-m-d H:i:s'; + + /** + * Use soft deletes in the table. + * @var bool + */ + protected $_softDeletes = true; + + /** + * **Created at** field name (if timestamps enabled). + * @var string + */ + protected $_createdField = 'created_at'; + + /** + * **Updated at** field name (if timestamps enabled). + * @var string + */ + protected $_updatedField = 'updated_at'; /** - * Sample model for Glowie application. - * @category Model - * @package glowieframework/glowie - * @author Glowie - * @copyright Copyright (c) Glowie - * @license MIT - * @link https://gabrielsilva.dev.br/glowie + * **Deleted at** field name (if soft deletes enabled). + * @var string */ - class Users extends Model{ - - /** - * Model table name. - * @var string - */ - protected $_table = 'users'; - - /** - * Model database connection name (from your app configuration). - * @var string - */ - protected $_database = 'default'; - - /** - * Table primary key name. - * @var string - */ - protected $_primaryKey = 'id'; - - /** - * Enable the use of UUIDs in the table. - * @var bool - */ - protected $_uuid = false; - - /** - * Table retrievable fields. - * @var array - */ - protected $_fields = []; - - /** - * Table updatable fields. - * @var array - */ - protected $_updatable = ['name', 'email', 'password']; - - /** - * Initial model attributes. - * @var array - */ - protected $_attributes = []; - - /** - * Table fields data types to cast. - * @var array - */ - protected $_casts = ['id' => 'int']; - - /** - * Table fields data types to mutate. - * @var array - */ - protected $_mutators = []; - - /** - * Handle timestamp fields. - * @var bool - */ - protected $_timestamps = true; - - /** - * Timestamp fields date format. - * @var string - */ - protected $_dateFormat = 'Y-m-d H:i:s'; - - /** - * Use soft deletes in the table. - * @var bool - */ - protected $_softDeletes = true; - - /** - * **Created at** field name (if timestamps enabled). - * @var string - */ - protected $_createdField = 'created_at'; - - /** - * **Updated at** field name (if timestamps enabled). - * @var string - */ - protected $_updatedField = 'updated_at'; - - /** - * **Deleted at** field name (if soft deletes enabled). - * @var string - */ - protected $_deletedField = 'deleted_at'; - - } - -?> \ No newline at end of file + protected $_deletedField = 'deleted_at'; +} diff --git a/app/public/assets/css/glowie.css b/app/public/assets/css/glowie.css index bab97ee..3d08982 100644 --- a/app/public/assets/css/glowie.css +++ b/app/public/assets/css/glowie.css @@ -1 +1 @@ -@import url(https://fonts.googleapis.com/css2?family=Montserrat:wght@200&display=swap);@import url(https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap);body{margin:0;padding:0;font-family:Montserrat,sans-serif;background:linear-gradient(90deg,#ed578b 0,#ed576a 100%);height:100vh;width:100vw}.main{height:100%;display:flex;align-items:center;justify-content:center;text-align:center;color:#fff}h1{font-size:150px;margin:0;color:#fff;opacity:.8}.text{margin-top:20px;opacity:.8;font-weight:300}h2{font-weight:400;font-size:24px}.menu{margin:50px 0}.menu a{color:#fff;text-decoration:none;text-transform:uppercase;margin:0 10px;font-weight:600}.menu a:hover{text-decoration:underline}.info{font-size:13px;opacity:.7}.login{background-color:#fff;color:#000;padding:30px;width:100%;max-width:400px;text-align:center;box-shadow:2px 2px 7px 2px rgb(0 0 0 / 20%)}.login input{display:block;width:100%;max-width:300px;margin:auto;margin-bottom:10px;font-family:'Open Sans',sans-serif;padding:7px 10px;font-size:15px;border-radius:5px;outline:0;border:1px solid #d3d3d3}.login .button{background-color:#ed578b;color:#fff;border:none;border-radius:5px;cursor:pointer;outline:0;font-family:'Open Sans',sans-serif;font-size:16px;padding:7px 20px;margin-top:10px;text-decoration:none;display:inline-block}.login .button.secondary{background-color:#78909c;margin-left:5px}.login .alert{background-color:#fff59d;font-family:'Open Sans',sans-serif;font-size:15px;padding:10px}.login #change-pw-form{display:none;margin-top:20px;background-color:#e5e5e5;padding:20px;border:1px solid #dcdcdc}.login #change-pw-form h3{margin:0 0 20px 0;font-size:18px}.login #change-pw-form.show{display:block}@media (prefers-color-scheme:dark){body{background:linear-gradient(90deg,#212121 0,#303030 100%)}} \ No newline at end of file +@import url(https://fonts.googleapis.com/css2?family=Montserrat:wght@200&display=swap);@import url(https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap);body{margin:0;padding:0;font-family:Montserrat,Helvetica,Tahoma,sans-serif;background:linear-gradient(90deg,#ed578b 0,#ed576a 100%);height:100vh;width:100vw}.main{height:100%;display:flex;align-items:center;justify-content:center;text-align:center;color:#fff}h1{font-size:150px;margin:0;color:#fff;opacity:.8}.text{margin-top:20px;opacity:.8;font-weight:300}h2{font-weight:400;font-size:24px}.menu{margin:50px 0}.menu a{color:#fff;text-decoration:none;text-transform:uppercase;margin:0 10px;font-weight:600}.menu a:hover{text-decoration:underline}.info{font-size:13px;opacity:.7}.login{background-color:#fff;color:#000;padding:30px;width:100%;max-width:400px;text-align:center;box-shadow:2px 2px 7px 2px rgb(0 0 0 / 20%)}.login input{display:block;width:100%;max-width:300px;margin:auto;margin-bottom:10px;font-family:'Open Sans',sans-serif;padding:7px 10px;font-size:15px;border-radius:5px;outline:0;border:1px solid #d3d3d3}.login .button{background-color:#ed578b;color:#fff;border:none;border-radius:5px;cursor:pointer;outline:0;font-family:'Open Sans',sans-serif;font-size:16px;padding:7px 20px;margin-top:10px;text-decoration:none;display:inline-block}.login .button.secondary{background-color:#78909c;margin-left:5px}.login .alert{background-color:#fff59d;font-family:'Open Sans',sans-serif;font-size:15px;padding:10px}.login #change-pw-form{display:none;margin-top:20px;background-color:#e5e5e5;padding:20px;border:1px solid #dcdcdc}.login #change-pw-form h3{margin:0 0 20px 0;font-size:18px}.login #change-pw-form.show{display:block}@media (prefers-color-scheme:dark){body{background:linear-gradient(90deg,#212121 0,#303030 100%)}} \ No newline at end of file diff --git a/app/public/index.php b/app/public/index.php index 2856a26..1065824 100644 --- a/app/public/index.php +++ b/app/public/index.php @@ -1,27 +1,26 @@ Composer packages were not found!
+ --------------------------------------------- + We do not recommend editing below this line. + --------------------------------------------- +*/ + +// Check Composer files +if (!file_exists('../../vendor/autoload.php')) { + die('Composer packages were not found!
Have you tried running composer install?'); - } +} - // Load Composer packages - require('../../vendor/autoload.php'); +// Load Composer packages +require('../../vendor/autoload.php'); - // Run Glowie bootstrapper - Application::run(); - -?> \ No newline at end of file +// Run Glowie bootstrapper +Application::run(); diff --git a/app/views/helpers/Helpers.php b/app/views/helpers/Helpers.php index b6541ee..8ae51b9 100644 --- a/app/views/helpers/Helpers.php +++ b/app/views/helpers/Helpers.php @@ -1,29 +1,29 @@ \ No newline at end of file +} diff --git a/app/views/layouts/default.phtml b/app/views/layouts/default.phtml index 588cedc..21227ae 100644 --- a/app/views/layouts/default.phtml +++ b/app/views/layouts/default.phtml @@ -1,16 +1,19 @@ - - - - - - - - - {{ $this->title }} - - - { content } - + + + + + + + + + + {{ $this->title }} + + + + { content } + + \ No newline at end of file diff --git a/firefly b/firefly index 517a058..8f26123 100644 --- a/firefly +++ b/firefly @@ -1,30 +1,29 @@ \ No newline at end of file +// Run Firefly +Firefly::run();