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.
1716namespace FloatPHP \Kernel ;
1817
1918use FloatPHP \Interfaces \Kernel \AuthenticationInterface ;
20- use FloatPHP \Classes \{
21- Http \Session , Http \Request ,
22- Security \Password ,
23- Filesystem \Arrayify
24- };
2519
2620abstract 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}
0 commit comments