PMA\libraries\plugins\auth\AuthenticationCookie::storeUserCredentials PHP Method

storeUserCredentials() public method

Stores user credentials after successful login.
public storeUserCredentials ( ) : void | boolean
return void | boolean
    public function storeUserCredentials()
    {
        global $cfg;
        // Name and password cookies need to be refreshed each time
        // Duration = one month for username
        $this->storeUsernameCookie($cfg['Server']['user']);
        // Duration = as configured
        // Do not store password cookie on password change as we will
        // set the cookie again after password has been changed
        if (!isset($_POST['change_pw'])) {
            $this->storePasswordCookie($cfg['Server']['password']);
        }
        // Set server cookies if required (once per session) and, in this case,
        // force reload to ensure the client accepts cookies
        if (!$GLOBALS['from_cookie']) {
            // URL where to go:
            $redirect_url = './index.php';
            // any parameters to pass?
            $url_params = array();
            if (strlen($GLOBALS['db']) > 0) {
                $url_params['db'] = $GLOBALS['db'];
            }
            if (strlen($GLOBALS['table']) > 0) {
                $url_params['table'] = $GLOBALS['table'];
            }
            // any target to pass?
            if (!empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') {
                $url_params['target'] = $GLOBALS['target'];
            }
            /**
             * Clear user cache.
             */
            Util::clearUserCache();
            Response::getInstance()->disable();
            PMA_sendHeaderLocation($redirect_url . URL::getCommonRaw($url_params), true);
            if (!defined('TESTSUITE')) {
                exit;
            } else {
                return false;
            }
        }
        // end if
        return true;
    }

Usage Example

 /**
  * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authSetUser (check for headers redirect)
  *
  * @return void
  */
 public function testAuthSetUserWithHeaders()
 {
     if (!defined('PMA_TEST_HEADERS')) {
         $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension');
     }
     $GLOBALS['PHP_AUTH_USER'] = '******';
     $arr = array('host' => 'a', 'port' => 1, 'socket' => true, 'ssl' => true, 'connect_type' => 'port', 'user' => 'pmaUser2');
     $GLOBALS['cfg']['Server'] = $arr;
     $GLOBALS['cfg']['Server']['host'] = 'b';
     $GLOBALS['cfg']['Server']['user'] = '******';
     $GLOBALS['cfg']['Servers'][1] = $arr;
     $GLOBALS['cfg']['AllowArbitraryServer'] = true;
     $GLOBALS['pma_auth_server'] = 'b 2';
     $GLOBALS['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'] = 'testPW';
     $GLOBALS['server'] = 2;
     $GLOBALS['cfg']['LoginCookieStore'] = true;
     $GLOBALS['from_cookie'] = false;
     $GLOBALS['cfg']['PmaAbsoluteUri'] = 'http://phpmyadmin.net/';
     $GLOBALS['collation_connection'] = 'utf-8';
     $restoreInstance = PMA\libraries\Response::getInstance();
     $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('disable'))->getMock();
     $mockResponse->expects($this->at(0))->method('disable');
     $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue($mockResponse);
     $this->object->authSetUser();
     $this->object->storeUserCredentials();
     $this->assertTrue(isset($_COOKIE['pmaServer-2']));
     // target can be "phpunit" or "ide-phpunit.php",
     // depending on testing environment
     $this->assertStringStartsWith('Location: http://phpmyadmin.net/index.php?', $GLOBALS['header'][0]);
     $this->assertContains('&target=', $GLOBALS['header'][0]);
     $this->assertContains('&server=2&lang=en&collation_connection=utf-8&token=token&PHPSESSID=', $GLOBALS['header'][0]);
     $attrInstance->setValue($restoreInstance);
 }
All Usage Examples Of PMA\libraries\plugins\auth\AuthenticationCookie::storeUserCredentials