Jump to content

How to programmatically login a user through Application/API


Recommended Posts

Posted

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);
		*/
		
		if($this->ipbwi_valid_classes[\IPS\Request::i()->content_type]){
			$content_type_class		= $this->ipbwi_valid_classes[\IPS\Request::i()->content_type];
		}else{
			$content_type_class		= \IPS\Request::i()->content_type;
		}
		
		$content = $content_type_class::load(\IPS\Request::i()->content_id);
		
		try
		{
			$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 );
	}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...