Skip to content

Commit

Permalink
Testing & refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Dec 6, 2023
1 parent f7a3241 commit 7273509
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,28 +693,45 @@ protected function doLogin(\Vespula\Auth\Auth $auth, array $credentials, string
$_msg = '';

try {

$potential_success_redirect_path = '';

/** @psalm-suppress MixedArrayOffset */
if( isset($_SESSION[static::SESSN_PARAM_LOGIN_REDIRECT]) ) {

////////////////////////////////////////////////////////////////
// There is an active session with a redirect url stored in it
//
// NOTE: we capture this value here because \Vespula\Auth\Auth->login()
// calls session_regenerate_id(true) under the hood which will delete
// old session data including this value we are capturing here.
/** @psalm-suppress MixedAssignment */
$potential_success_redirect_path = $_SESSION[static::SESSN_PARAM_LOGIN_REDIRECT];
}

$auth->login($credentials); //try to login

if( $auth->isValid() ) {
if( $auth->isValid() ) { // login successful

/** @psalm-suppress MixedAssignment */
$_msg = $this->getAppSetting('base_controller_do_login_auth_is_valid_msg');

//since we are successfully logged in, resume session if any
if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); }


/** @psalm-suppress MixedAssignment */
$success_redirect_path =
($potential_success_redirect_path !== '')
? $potential_success_redirect_path : $success_redirect_path;

/** @psalm-suppress MixedArrayOffset */
if( isset($_SESSION[static::SESSN_PARAM_LOGIN_REDIRECT]) ) {

//there is an active session with a redirect url stored in it
/** @psalm-suppress MixedAssignment */
$success_redirect_path = $_SESSION[static::SESSN_PARAM_LOGIN_REDIRECT];

//since login is successful remove stored redirect url,
//it has served its purpose & we'll be redirecting now.
unset($_SESSION[static::SESSN_PARAM_LOGIN_REDIRECT]);
}

//since we are successfully logged in, resume session if any
if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); }

} else {
/** @psalm-suppress MixedAssignment */
$_msg = $this->getAppSetting('base_controller_do_login_auth_not_is_valid_msg');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);


namespace SMVCTools\Tests\TestObjects;

/**
* Description of ControllerWithPublicDoLogin
*
* @author rotimi
*/
class ControllerWithPublicDoLogin extends \SlimMvcTools\Controllers\BaseController {

public function doLoginPublic(\Vespula\Auth\Auth $auth, array $credentials, string &$success_redirect_path): string {

return $this->doLogin($auth, $credentials, $success_redirect_path);
}
}

0 comments on commit 7273509

Please sign in to comment.