Skip to content

Commit e8d5bda

Browse files
committed
Update
- Used traits - Updated core
1 parent 1131791 commit e8d5bda

19 files changed

+1450
-1262
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 FloatPHP
3+
Copyright (c) 2024 FloatPHP
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# FloatPHP (Kernel)
22

3-
<img src="https://www.floatphp.com/assets/img/floatphp.png" width="100" alt="Micro PHP framework">
3+
<img src="https://floatphp.com/assets/img/floatphp.png" width="100" alt="Micro PHP framework">
44

55
FloatPHP **Kernel Components**.
6+
Used to setup WEB application using all other components.
67

78
## ⚡ Installing:
89

composer.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
{
22
"name": "floatphp/kernel",
3-
"version" : "1.0.2",
3+
"version" : "1.1.0",
44
"type": "library",
55
"description": "FloatPHP Kernel Components",
66
"keywords": ["php","micro-framework","framework","PSR","ORM","jakiboy","composer"],
7-
"homepage": "https://www.floatphp.com/",
7+
"homepage": "https://floatphp.com",
88
"license": "MIT",
99
"authors": [
1010
{
1111
"name": "Jihad Sinnaour",
1212
"email": "[email protected]",
1313
"role": "Founder"
14-
},
15-
{
16-
"name": "Softgine",
17-
"email": "[email protected]",
18-
"role": "Developer"
1914
}
2015
],
2116
"require": {
@@ -24,11 +19,11 @@
2419
"ext-intl": "*",
2520
"twig/twig": "^3.5.1",
2621
"justinrainbow/json-schema": "^5.2.12",
27-
"floatphp/classes": "^1.0.2",
28-
"floatphp/helpers": "^1.0.2",
29-
"floatphp/interfaces": "^1.0.2",
30-
"floatphp/exceptions": "^1.0.2",
31-
"floatphp/cli": "^1.0.2"
22+
"floatphp/classes": "^1.1.0",
23+
"floatphp/helpers": "^1.1.0",
24+
"floatphp/interfaces": "^1.1.0",
25+
"floatphp/exceptions": "^1.1.0",
26+
"floatphp/cli": "^1.1.0"
3227
},
3328
"autoload": {
3429
"psr-4" : {

src/AbstractAuthController.php

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22
/**
3-
* @author : JIHAD SINNAOUR
3+
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.0.2
7-
* @category : PHP framework
8-
* @copyright : (c) 2017 - 2023 Jihad Sinnaour <[email protected]>
9-
* @link : https://www.floatphp.com
6+
* @version : 1.1.0
7+
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
8+
* @link : https://floatphp.com
109
* @license : MIT
1110
*
1211
* This file if a part of FloatPHP Framework.
@@ -17,30 +16,25 @@
1716
namespace FloatPHP\Kernel;
1817

1918
use FloatPHP\Interfaces\Kernel\AuthenticationInterface;
20-
use FloatPHP\Classes\{
21-
Http\Session, Http\Request,
22-
Security\Password,
23-
Filesystem\Arrayify
24-
};
2519

2620
abstract class AbstractAuthController extends BaseController
2721
{
2822
/**
2923
* @access public
30-
* @param void
3124
* @return void
3225
*/
3326
abstract public function login();
3427

3528
/**
29+
* Check whether current user is authenticated.
30+
*
3631
* @access public
37-
* @param void
3832
* @return bool
3933
*/
4034
public function isAuthenticated() : bool
4135
{
42-
if ( Session::isSetted($this->getSessionId()) ) {
43-
return $this->isLoggedIn();
36+
if ( $this->getSession($this->getSessionId()) ) {
37+
return $this->isValidSession();
4438
}
4539
return false;
4640
}
@@ -57,70 +51,63 @@ protected function authenticate(AuthenticationInterface $auth, $args = [])
5751
$this->verifyRequest(true);
5852

5953
// Get authentication
60-
$args = Arrayify::merge([
61-
'username' => false,
62-
'password' => false
63-
],$args);
64-
65-
if ( !$args['username'] ) {
66-
$args['username'] = Request::get('username');
67-
}
68-
if ( !$args['password'] ) {
69-
$args['password'] = Request::get('password');
70-
}
54+
$args = $this->mergeArray([
55+
'username' => $this->getRequest('username'),
56+
'password' => $this->getRequest('password')
57+
], $args);
7158

7259
// Authenticate override
73-
$this->doAction('authenticate',$args['username']);
60+
$this->doAction('authenticate', $args['username']);
7461

7562
// Verify authentication
7663
if ( ($user = $auth->getUser($args['username'])) ) {
7764

7865
// Check password
79-
if ( Password::isValid($args['password'],$user['password']) ) {
66+
if ( $this->isPassword($args['password'], $user['password']) ) {
8067

8168
// Check password format
82-
if ( $this->applyFilter('authenticate-strong-password',false) ) {
83-
if ( !Password::isStrong($args['password']) ) {
84-
// Authenticate failed response
85-
$msg = $this->applyFilter('authenticate-password-message','Strong password required');
69+
if ( $this->applyFilter('authenticate-strong-password', false) ) {
70+
if ( !$this->isStrongPassword($args['password']) ) {
71+
// Authenticate failed
72+
$msg = $this->applyFilter('authenticate-password-message', 'Strong password required');
8673
$msg = $this->translate($msg);
87-
$this->setResponse($msg,[],'warning');
74+
$this->setResponse($msg, [], 'warning');
8875
}
8976
}
9077

9178
// Register session
92-
Session::register($this->getAccessExpire());
79+
$this->registerSession($this->getAccessExpire());
9380

94-
// Check session registred
95-
if ( $this->isLoggedIn() ) {
81+
// Check valid session
82+
if ( $this->isValidSession() ) {
9683

9784
if ( $auth->hasSecret($args['username']) ) {
98-
Session::set('--verify',$args['username']);
99-
// Authenticate accepted response
100-
$msg = $this->applyFilter('authenticate-accepted-message','Accepted');
85+
$this->setSession('--verify', $args['username']);
86+
// Authenticate accepted
87+
$msg = $this->applyFilter('authenticate-accepted-message', 'Accepted');
10188
$msg = $this->translate($msg);
102-
$this->setResponse($msg,[],'accepted',202);
89+
$this->setResponse($msg, [], 'accepted', 202);
10390

10491
} else {
105-
Session::set($auth->getKey(),$user[$auth->getKey()]);
106-
// Authenticate success response
107-
$msg = $this->applyFilter('authenticate-success-message','Connected');
92+
$this->setSession($auth->getKey(),$user[$auth->getKey()]);
93+
// Authenticate success
94+
$msg = $this->applyFilter('authenticate-success-message', 'Connected');
10895
$msg = $this->translate($msg);
10996
$this->setResponse($msg);
11097
}
11198

11299
} else {
113-
Session::end();
100+
$this->endSession();
114101
}
115102
}
116103
}
117104

118105
// Authenticate failed override
119-
$this->doAction('authenticate-failed',$args['username']);
106+
$this->doAction('authenticate-failed', $args['username']);
120107

121-
// Authenticate failed response
122-
$msg = $this->applyFilter('authenticate-error-message','Authentication failed');
108+
// Authenticate failed
109+
$msg = $this->applyFilter('authenticate-error-message', 'Authentication failed');
123110
$msg = $this->translate($msg);
124-
$this->setResponse($msg,[],'error',401);
111+
$this->setResponse($msg, [], 'error', 401);
125112
}
126113
}

src/ApiController.php

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22
/**
3-
* @author : JIHAD SINNAOUR
3+
* @author : Jakiboy
44
* @package : FloatPHP
55
* @subpackage : Kernel Component
6-
* @version : 1.0.2
7-
* @category : PHP framework
8-
* @copyright : (c) 2017 - 2023 Jihad Sinnaour <[email protected]>
9-
* @link : https://www.floatphp.com
6+
* @version : 1.1.0
7+
* @copyright : (c) 2018 - 2024 Jihad Sinnaour <[email protected]>
8+
* @link : https://floatphp.com
109
* @license : MIT
1110
*
1211
* This file if a part of FloatPHP Framework.
@@ -16,54 +15,51 @@
1615

1716
namespace FloatPHP\Kernel;
1817

19-
use FloatPHP\Classes\{
20-
Http\Server,
21-
Security\Encryption,
22-
Filesystem\Stringify
23-
};
24-
2518
class ApiController extends BaseController
2619
{
2720
/**
28-
* Is HTTP authenticated.
21+
* Is HTTP authenticated (Basic).
2922
*
3023
* @access public
31-
* @param void
3224
* @return bool
25+
* @uses initConfig()
3326
*/
3427
public function isHttpAuthenticated() : bool
3528
{
3629
// Init configuration
3730
$this->initConfig();
3831

3932
// Basic authentication
40-
if ( $this->applyFilter('basic-authentication',true) ) {
41-
if ( Server::isBasicAuth() ) {
42-
$username = Server::getBasicAuthUser();
43-
$password = Server::getBasicAuthPwd();
33+
if ( $this->applyFilter('basic-authentication', true) ) {
34+
if ( $this->isBasicAuth() ) {
35+
36+
$username = $this->getBasicAuthUser();
37+
$password = $this->getBasicAuthPwd();
38+
4439
// API authenticate override
45-
$this->doAction('api-authenticate',[
40+
$this->doAction('api-authenticate', [
4641
'username' => $username,
47-
'address' => Server::getIP(),
42+
'address' => $this->getServerIp(),
4843
'method' => 'basic'
4944
]);
45+
5046
if ( $username == $this->getApiUsername()
51-
&& $password == $this->getApiPassword() ) {
47+
&& $password == $this->getApiPassword() ) {
5248
return true;
5349
}
5450
}
5551
}
5652

5753
// Bearer token authentication
58-
if ( $this->applyFilter('bearer-authentication',true) ) {
59-
if ( ($token = Server::getBearerToken()) ) {
54+
if ( $this->applyFilter('bearer-authentication', true) ) {
55+
if ( ($token = $this->getBearerToken()) ) {
6056
return $this->isGranted($token);
6157
}
6258
}
6359

6460
// Extra authentication
65-
if ( $this->applyFilter('extra-authentication',false) ) {
66-
return $this->applyFilter('extra-authenticated',false);
61+
if ( $this->applyFilter('extra-authentication', false) ) {
62+
return $this->applyFilter('extra-authenticated', false);
6763
}
6864

6965
return false;
@@ -76,26 +72,28 @@ public function isHttpAuthenticated() : bool
7672
* @param string $token
7773
* @return bool
7874
*/
79-
protected function isGranted($token) : bool
75+
protected function isGranted(string $token) : bool
8076
{
81-
$encryption = new Encryption($token, $this->getSecret(true));
82-
$access = $encryption->decrypt();
83-
$pattern = '/{user:(.*?)}{pswd:(.*?)}/';
84-
$username = Stringify::match($pattern,$access,1);
85-
$password = Stringify::match($pattern,$access,2);
77+
$access = $this->getTokenAccess($token, $this->getSecret(true));
78+
$username = $this->matchString($this->getTokenPattern(), $access, 1);
79+
$password = $this->matchString($this->getTokenPattern(), $access, 2);
8680

8781
if ( $username && $password ) {
82+
8883
// API authenticate override
89-
$this->doAction('api-authenticate',[
84+
$this->doAction('api-authenticate', [
9085
'username' => $username,
91-
'address' => Server::getIP(),
86+
'address' => $this->getServerIp(),
9287
'method' => 'token'
9388
]);
89+
90+
// Match authentication
9491
if ( $username == $this->getApiUsername()
95-
&& $password == $this->getApiPassword() ) {
92+
&& $password == $this->getApiPassword() ) {
9693
return true;
9794
}
9895
}
96+
9997
return false;
10098
}
10199
}

0 commit comments

Comments
 (0)