On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I've dabbled with Modx before but this is the first time I've ever tried my hand at a plugin.

    I've written the following plugin to authenticate users against a third party database. The System Events OnWebAuthentication is enabled.

    if ($modx->event->name == 'OnWebAuthentication') {
        
            $ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,'{urlhere}');
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    	$output = curl_exec($ch);
    	curl_close($ch);		
    		
    	if($output == '1')
    	{
                   $modx->event->output(true);
    	}else{
    	       $modx->event->output(false);
    	}
    
    }



    I'm using the standard login Package but my plugin isn't being triggered? how do I trigger it?
    • I suspect that your plugin is running.

      Try putting this at the top and check the error log in the Manager:

      $modx->log->(modX::LOG_LEVEL_ERROR, "Plugin Executed");


      Does your cURL call return '1' exactly when the user is valid? If so it would be safer to use === '1'.

      For the end of your code, instead of the if statement, try this (note the underscore on _output):

      $modx->event->_output =  ! empty($output);
      return '';


      If it works, try changing it to this safer version:

      $modx->event->_output =  $output === '1';
      return '';


      You may have to do it this way:

      $modx->event->_output =  trim($output) === '1';
      return '';




        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • First, create resource that required user to login. IMHO.
          zaenal.lokamaya