MyBB Community Forums

Full Version: Mybb restfull api not returning user object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
https://github.com/mohamedbenjelloun/MyB...API-System

I have problem with post request to the rest api. Before it was working fine but now it stopped returning any values.

I MAKE here request
https://MYDOMAIN.com/api.php/authenticate

with content type:  application/x-www-form-urlencoded,
username,
password,
apikey,
and got success 200 OK - no body returned for response[Image: LdkEfg8.jpg]


<?php

# This file is a part of MyBB RESTful API System plugin - version 0.2
# Released under the MIT Licence by medbenji (TheGarfield)
# 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

/**
This interface should be implemented by APIs, see VersionAPI for a simple example.
*/
class AuthenticateAPI extends RESTfulAPI {
 
 public function info() {
 return array(
 "name" => "Authentication",
 "description" => "This API exposes authentication interface.",
 "default" => "activated"
 );
 }
 /**
 This is where you perform the action when the API is called, the parameter given is an instance of stdClass, this method should return an instance of stdClass.
 */
 public function action() {
 global $mybb, $db;
 if($this->is_authenticated()) {
 return $this->get_user();
 }
 elseif(isset($mybb->input["sessionid"]) && is_string($mybb->input["sessionid"])) {
 $sid = $db->escape_string($mybb->input["sessionid"]);
 $query = $db->query("SELECT s.uid FROM " . TABLE_PREFIX . "sessions s WHERE s.sid = '{$sid}'");
 $result = $db->fetch_array($query);
 if(empty($result)) {
 throw new UnauthorizedException("Not connected.");
 }
 else {
 $uid = $result['uid']; // no need to escape this, it's just been retrieved from db 23067
 $query = $db->query("
 SELECT u.*, f.*
 FROM ".TABLE_PREFIX."users u
 LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
 WHERE u.uid='$uid'
 LIMIT 1
 ");
 $user = (object) $db->fetch_array($query);
 if(empty($user)) {
 throw new UnauthorizedException("Not connected");
 }
 $user->ismoderator = is_moderator("", "", $uid);
 //return $user;
 return $uid;
 }
 }
 else {
 throw new UnauthorizedException("Not connected.");
 }
 }
}

---------------------------------------------------------------------------------------
----------------------------- EDITED 22.05 --------------------------------------------
---------------------------------------------------------------------------------------

After writing this post it fixed, dont know why. And today again I have the same problem.



I hade made manually set uid and tried on my phpmyadmin - SQL SELECT user from this script and it has user object with data becouse 
otherwise there would be outputted error. 
User object is not empty but dont know why there is a white page returned 200 success.














up please help