Reputation: 51921
We need to provide a simple REST-like web service interface for communicating with a 3rd party website:
Remote call to us:
https:/www.oursite.com/user/{ID}/logged_on
Returns to remote site:
"YES" | "NO"
The web service should be capable of:
ID
in the above example)Do I need to write a custom module for that purpose?
Upvotes: 0
Views: 2340
Reputation: 2344
I recommend the Services module.
When that is setup you can make a remote call to, e.g.:
http://www.example.com/my_services_path/system/connect http://www.example.com/my_services_path/system/connect.json
This will return XML (or JSON) to you indicating whether or not the current user is logged in. You will need to parse the returned result to see the user object results.
To check whether or not a certain UID is logged in, you will need to enable the 'User -> Retrieve' resource, then you can make a call to, e.g.:
http://www.example.com/my_services_path/user/1 http://www.example.com/my_services_path/user/1.json
This will return a Drupal user object in XML (or JSON).
To my knowledge it doesn't contain a variable indicating whether or not the user is logged in. It does contain their last login time, status, etc.
You may have to do a little customization via the hook_user 'load' operation in your module to attach a custom variable, e.g. $user->is_logged_in and set its value dynamically. Then a 'User -> Retrieve' service call would contain that variable for you.
Now that I wrote up this answer, I see that you would like a plain text result, doh! Well, then I would recommend the answer from @zeroFiG.
Upvotes: 4
Reputation: 2369
You will need your own module for this, inside you should put this:
function MODULENAME_menu() {
$items = array();
$items['user/%/logged_on'] = array(
'title' => 'Ajax Dessins',
'page callback' => 'MODULENAME_check_user_status',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items
}
function MODULENAME_check_user_status($uid) {
// Do the lookup / checking
// and then something like:
echo $result;
exit();
}
Replace "MODULENAME_" with the name of your module, and that should do the trick. This is assuming you have Drupal 6. It should be similar enough with drupal 5/7; the only differences are in the menu declaration.
Upvotes: 3
Reputation: 3414
Try this function out drupal_http_request. Yes you have to write custom module and call this function out.
Upvotes: 1