We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36510
    • 10 Posts
    hello,

    i try to make authentication for a RSS feed. i’m using MODx Revolution 2.0.0-rc-1 rev6614 and login pl 1.0.1

    this is +/- the code of my snippe:

    // check authentication
    if ( (!isset($_SERVER['PHP_AUTH_USER'])) ) {
        header('WWW-Authenticate: Basic realm="Private Area"'); 
        header("HTTP/1.1 401 Unauthorized"); 
        print "This page requires authorisation.";
        exit(); 
    }else{
    	// check if modx user
    	$_POST['username'] = $_SERVER['PHP_AUTH_USER'];
    	$_POST['password'] = $_SERVER['PHP_AUTH_PW'];
            
            $response = $modx->executeProcessor(array(
                'action' => 'login',
                'location' => 'security'
            ));
    	
    	// check if login successfull
            if (!empty($response) && is_array($response) && !empty($response['success']) && isset($response['object']) ) {
    		
    		// check if user is authenticated and create feed
    		echo 'isAut:[' . $modx->user->isAuthenticated($modx->context->get('key')) . ']';
    		echo 'isMember:[' . $modx->isMemberOfWebGroup(array('ContentEditor','Administrator')) . ']';
    		
    	}else{
    		header("WWW-Authenticate: Basic realm=\"Private Area\"");
    		header("HTTP/1.0 401 Unauthorized");
    	        print "This page requires authorisation.";
    		exit;	
    	}
    }


    the first time i hit the page with correct login information i get this output:

    isAut:[1]isMember:[]

    if i refresh the page i get this:

    isAut:[1]isMember:[1]

    why do i need to refresh the page to get correct response from MemberOfWebGroup

    also is there a more proper way to set username and password $scriptProperties[’username’]=$_SERVER[’PHP_AUTH_USER’] does not work or i’m just wrong with this at all?

    thank you very much for any feedback
      Home is where the hard disk is:
      http://sofasurfer.org