IPBWI.com Matthias Reuter
March 27, 2016 in Developer Connection
I'm working on a REST-API for "reports" object. If utilizing method "report" (/ipb/system/Content/Content.php), the "report_by" field in line 810 will be set to currently logged in user:
'report_by' => (int) \IPS\Member::loggedIn()->member_id,
So my question is: How can I set the logged in user for a REST API call? Otherwise all actions performed and all permission checks will be based upon guest role what's limiting possible features drastically.
So here is my current state:
public function POSTindex()
/* this doesn't load a member as logged in globally.
$member_id = \IPS\Request::i()->member_id;
$member = \IPS\Member::load($member_id);
$content_type_class = $this->ipbwi_valid_classes[\IPS\Request::i()->content_type];
$content_type_class = \IPS\Request::i()->content_type;
$content = $content_type_class::load(\IPS\Request::i()->content_id);
$r = $content->report(\IPS\Request::i()->report_message); // cannot set a reporting member ID here, method uses currently logged in member only
catch ( \OutOfRangeException $e )
throw new \IPS\Api\Exception( 'INVALID_ID', '2C292/7', 404 );
return new \IPS\Api\Response( 201, (array)$r );
\IPS\Member::$loggedInMember = \IPS\Member::load($member_id);
Disclaimer: I haven't actually tested this, so don't blame me if it makes your server explode. It ought to work though.
you are aweseome! Just works. How can I thank you?
This topic is now archived and is closed to further replies.
Started 1 hour ago
Started 3 hours ago
Started Yesterday at 05:54 PM