I am having an issue with the ACL of my Joomla API. I created this using the TechJoomla api component.
I have the following code to handle post requests on my api.
<?php
use Joomla\CMS\Factory;
class WdtoptionsApiResourceOptions extends ApiResource
{
public function post()
{
$user = Factory::getUser();
$accessLevels = $user->getAuthorisedViewLevels();
$result = new \stdClass;
//check the user has the required access levels.
if (!in_array(9, $accessLevels))
{
$result-> options->{'Error'} = 'Could not access api. Are you logged in?';
}
else
{
//I process the response for a valid user here.
}
$this->plugin->setResponse( $result );
}
}
?>
For a user who has selected the 'Remember Me' check box at the login page it works correctly.
For a user who has not selected the 'Remember Me' check box at the login page, the error code appears and the user is immediately logged out.
How do I change this code to deal with users that don't have a 'remember me' cookie set?
Are these users still 'logged in'? Or do they fall into some other category?
I suspect the answer is to use the JFactory::getSession()
function described here. But I can't work out how to use this function.
https://docs.joomla.org/Using_the_JFactory_class