Skip to content

Commit

Permalink
Updates to new core version
Browse files Browse the repository at this point in the history
  • Loading branch information
eugabrielsilva committed Feb 29, 2024
1 parent 14f2e7d commit 2365ba1
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 18 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Glowie is a PHP framework designed to be as light, fast and powerful as possible
- Large compatibility with all basic hosting providers
- and many more...

## Only what you need
Forget about those fancy frameworks with thousands of useless functions and classes with stuff you will never use. Glowie is packed with only what you need for your application to run smoothly.

## Getting started
[Explore the documentation](https://eugabrielsilva.tk/glowie/docs) to know how to start using Glowie to create something awesome.
Expand Down
6 changes: 3 additions & 3 deletions app/commands/Quote.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Glowie\Commands;

use Util;
use Glowie\Core\Collection;
use Glowie\Core\CLI\Command;

/**
Expand All @@ -20,7 +20,7 @@ class Quote extends Command{
*/
public function run(){
// Gets a random quote
$quote = Util::randomArray([
$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."',
Expand All @@ -33,7 +33,7 @@ public function run(){
'"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);
Expand Down
10 changes: 6 additions & 4 deletions app/config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@

// 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,
'Cache' => \Glowie\Core\Tools\Cache::class,
'Crawler' => \Glowie\Core\Tools\Crawler::class,
'Mailer' => \Glowie\Core\Tools\Mailer::class,
Expand All @@ -201,14 +203,14 @@
// Application miscellaneous settings
'other' => [

// Application URL (for CLI route mocking only)
'url' => 'http://localhost',

// Default language
'language' => 'en',

// Default timezone
'timezone' => 'America/Sao_Paulo',

// Request variables precedence
'request_vars' => 'GET_POST'
'timezone' => 'America/Sao_Paulo'

]

Expand Down
13 changes: 7 additions & 6 deletions app/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Glowie\Core\Tools\Validator;
use Glowie\Core\Tools\Authenticator;
use Babel;

/**
* Login controller for Glowie application.
Expand Down Expand Up @@ -60,7 +61,7 @@ public function login(){
public function submitLogin(){
// Validate POST data
if(!(new Validator())->validateFields($this->post, self::VALIDATION_RULES)){
$this->session->setFlash('alert', 'Invalid login information!');
$this->session->setFlash('alert', Babel::get('auth.invalid_login'));
return $this->response->redirectRoute('login');
}

Expand All @@ -73,11 +74,11 @@ public function submitLogin(){
// Show error message
switch ($auth->getError()) {
case Authenticator::ERR_NO_USER:
$this->session->setFlash('alert', 'This user does not exist!');
$this->session->setFlash('alert', Babel::get('auth.invalid_user'));
break;

case Authenticator::ERR_WRONG_PASSWORD:
$this->session->setFlash('alert', 'Incorrect password!');
$this->session->setFlash('alert', Babel::get('auth.invalid_password'));
break;
}

Expand All @@ -104,13 +105,13 @@ public function dashboard(){
public function changePassword(){
// Validate POST data
if(!(new Validator())->validateMultiple([$this->post->password, $this->post->password_confirm], 'required')){
$this->session->setFlash('alert', 'Passwords cannot be empty!');
$this->session->setFlash('alert', Babel::get('auth.password_empty'));
return $this->response->redirectRoute('dashboard');
}

// Check if passwords match
if($this->post->password !== $this->post->password_confirm){
$this->session->setFlash('alert', "Passwords don't match!");
$this->session->setFlash('alert', Babel::get('auth.password_mismatch'));
return $this->response->redirectRoute('dashboard');
}

Expand All @@ -122,7 +123,7 @@ public function changePassword(){
(new Authenticator())->refresh();

// Redirect back to the dashboard
$this->session->setFlash('alert', 'Password changed!');
$this->session->setFlash('alert', Babel::get('auth.password_changed'));
$this->response->redirectRoute('dashboard');
}

Expand Down
26 changes: 26 additions & 0 deletions app/languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@
// 503 error message
'service_unavailable' => 'We will be back soon'

],

// Auth demo messages
'auth' => [

// Login required
'login_required' => 'You must login first!',

// Invalid login info
'invalid_login' => 'Invalid login information!',

// User not found
'invalid_user' => 'This user does not exist!',

// Wrong password
'invalid_password' => 'Incorrect password!',

// Password validation
'password_empty' => 'Passwords cannot be empty!',

// Password confirm validation
'password_mismatch' => "Passwords don't match!",

// Password changed message
'password_changed' => 'Password changed!',

]

];
Expand Down
3 changes: 2 additions & 1 deletion app/middlewares/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Glowie\Core\Http\Middleware;
use Glowie\Controllers\Login;
use Glowie\Core\Tools\Authenticator;
use Babel;

/**
* Authentication middleware for Glowie application.
Expand Down Expand Up @@ -42,7 +43,7 @@ public function handle(){
public function fail(){
// Clear session data and redirect to login
(new Authenticator())->logout();
$this->session->setFlash('alert', 'You must login first!');
$this->session->setFlash('alert', Babel::get('auth.login_required'));
$this->response->redirectRoute('login');
}

Expand Down
16 changes: 16 additions & 0 deletions app/middlewares/ValidateCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Glowie\Middlewares;

use Glowie\Core\Http\Middleware;
use Babel;

/**
* CSRF token validation middleware for Glowie application.
Expand All @@ -27,6 +28,21 @@ public function handle(){
return $this->request->checkCsrfToken($token);
}

/**
* 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')
]);
}

}

?>
4 changes: 3 additions & 1 deletion app/views/dashboard.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
</div>
</div>

{ push('scripts') }
<script>
function toggleChangeForm() {
document.getElementById('change-pw-form').classList.toggle('show');
}
</script>
</script>
{ /push }
2 changes: 1 addition & 1 deletion app/views/helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Helpers{

/**
* Returns the page rendering time.
* @return float Page rendering time.
* @return string Page rendering time.
*/
public function getRenderTime(){
return round((microtime(true) - APP_START_TIME) * 1000, 2) . 'ms';
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/default.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
</head>
<body>
{ content }
{ stack('scripts') }
</body>
</html>

0 comments on commit 2365ba1

Please sign in to comment.