I have a Flash application that is hosted from within a Drupal page. Some parts of the Flash application should be available to all users, but some should only be available to a logged-in user. (The specific role doesn’t matter, just that they are any authorized user of the site).
From within Flash, I can detect whether the user is logged on by screen-scraping the ‘?q=user’ page, but this is very brittle. What is the ‘right’ way to do this? I can install additional Modules if necessary, but they need to be compatible with Drupal 6, not 5.
Similarly, if there is no user currently logged in, how can I take a username and password that they provide to me and log them in (or determine that the password is bad)?
I was able to do this using Drupal’s ‘system’ and ‘user’ services:
As of this writing, the AMFPHP service is not yet ported to Drupal 6, so I used XMLRPC. To use XMLRPC from ActionScript, I used the helper library at as3-rpclib. This library was written for ActionScript2, so using it with Flex3 required me to patch it, as described on this page (scroll down the page and search for a comment on May 10, 2008, by ‘jameshyu’).
Once all those prerequisites are taken care of, you can check the currently logged-in user (if any) and/or log in a user with code like the following.
Here’s the module that actually implements the login:
and here’s an example of using it: