Sign up ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a Javascript application that I start from a drupal website. I need to save data from the Javascript application to the server, only logged in users can save data.

So I have made a custom php webservice that handles request from the Javascript application. Within this webservice I call drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION) and then inspect the $user object. Like this:

drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
global $user;
$userid = isset($user) && isset($user->uid) ? $user->uid : 0;
return $userid

When I receive a valid userid I allow the user to save specific data for his account.

Is this a save way to do it? Are there any security considerations I overlooked?

Extra background information:

  • I want a minimal solution, so the services module is not what I am looking for.

  • I don't need to access drupal content or functionality, just my own php functions to exchange data between the client and the server.

  • I don't need user login/authentication functionality in the javascript application. Login is done on the drupal website. If the user is not logged in when using the js application, he may still use it but cannot save data. This is enforced by the PHP code.

share|improve this question
    
I'd suggest you try accomplish this using the Services module, which in my opinion is de facto for drupal web services and if memory serves me right has an out of the box user authentication service all of which would save time and have good support. –  optimusprime619 Oct 22 '13 at 17:13
    
Thanks, didn't know about that module. Still I also would like to know if my approach as described is safe to use. In my situation the user is already logged in. The webapplication is started from the same session, so I only have to check for a valid user object. –  Asimov Oct 22 '13 at 18:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.