Hey,

I am currently investigating Drupal for my website. It's a community based site, so I want to use my current user database. A previous solution I had was to create the existing users into drupal users, and then when somebody signed up it would automatically create a drupal user. In hindsight, while it works, it's quite a redundant method, because I already have the users stored in another database.

My Drupal site will have no methods for doing anything in regards to the user account, i.e editing. This will all be handled via my other system. I am considering changing how the user module works, or perhaps overriding it with a custom module. My current train of thought would be to check if the user if logged in on my other system, if so, populate the global $user in Drupal. Is this the right way of going about it, and also is the user module responsible for getting the username of the owner of content, because I would also need to override that.

I basically need to know the minimum I would need to change to implement such a system.

Any help would be greatly appreciated.

-Al

Comments

markj’s picture

Hi,

I've written a 6.x module that enables you to write an authentication plugin for arbitrary external systems. It's not up on d.o. at the moment but you can get it here: http://drupalib.interoperating.info/ilsauthen

Mark

IceMazza’s picture

But this still requires a login on the page? The integration I have in mind into my old system would be a simple check of a global array which includes a user id and username which I can use to populate the drupal global $user. There should be no logging in via Drupal. Or am I misunderstanding your code?

markj’s picture

Sorry, I misunderstood what you were asking. My module still requires the user to log into Drupal.

IceMazza’s picture

Ah ok, thanks for trying to help.

I think for what I want to do I will have to tweak the user and node modules.

From what I gather I would need to override node_load to adjust the username (from my old database), and as for automatic loggin in, I am guessing I could probably get away with setting $user->uid, $user->name and the roles manually to achieve it. My only concern is that there are other areas of the codebase that will rely on actual users being present in the drupal database.

Any other takers?

IceMazza’s picture

I'm considering creating a module to achieve it.

module_init()

  • Check the external user data
  • If valid, populate the Drupal $user variable. uid, name, roles etc.

module_nodeapi()

  • Replace $node->name with username from external user data (fetched by passing $node->uid)

Can any Drupal veterans forsee any problems with this?

markj’s picture

Your population of $user would need to happen after core populates it (with the anonymous user, I assume). I think the first thing you should make sure is that your module is invoked immediately after user.module. You may need to tweak your module's weight setting in the system table to do this. See http://drupal.org/node/110238 for more info.

IceMazza’s picture

I found some problems with changing the username in nodeapi. When you try to submit your node, it tries to resolve the username then, which of course will fail. Of course you could switch on the $op, but it's probably cleaner and more reliable to have them in the database.

One difference is that rather than entering them into the database initially, I will create them on the fly on their first visit to the drupal main page. Then it will be easier to just log them in legitimately via the user system in code.

Thanks again for your help.

markj’s picture

My module creates users on the fly, not when they visit the home page, but when the remote system returns true. Feel free to take whatever of it you want.

IceMazza’s picture

Thanks, but I've already coded it. It was just a couple of lines, plus I already have the login code from before.