Adding/removing user role on his login - based on non-Drupal table
Hello Chris and fellow Drupal users,
I've discovered your site yesterday while searching for my Drupal problem and the videos are awesome!
My question:
I have recently transferred a Flash/Perl card game with about 4000 users from using phpBB 3 as backend to Drupal 7 and it has worked well, but I'm hesitant to enable the forum - because some users at my old site had been freaking me out.
I would like to offer a forum at my site again, but only to the users who are playing long enough at my site and have a good enough reputation. Both informations (how many games played + reputation) are maintained by my Perl-game and are kept in non-Drupal tables (but in the same database as the Drupal tables). And I have created a Drupal user role of "trusted users".
I could modify 2 spots in my game - where the games are counted and where reputation is being changed - and then call 'insert/delete from users_roles where uid=?', but maybe there is a better spot in Drupal, where I could change a user role on his login?
I.e. a user visits my site, his reputation and number of games are checked by 2 quick select queries against my non-Drupal tables and then he's added (or removed - if his reputation has decreased) to the "trusted users" role and can write in forum + blog.
Thank you
Alex
Hi Alex,
I'm happy to hear that you're finding the site useful. :)
In terms of a solution for when to add the role to a user, it seems like from a workflow point of view, both seem like they'd work. If you were doing it on login, you could add the role adding to hook_user_login (http://api.drupal.org/api/drupal/modules--user--user.api.php/function/ho...). It feels like from a workflow point of view, it would be good to add the role from in the game, since it would be more timely, but it depends on how immediate you need the change.
Sounds like you're on the right track thinking about hooking into Drupal for things like this, though. Feel free to post back with any followup questions.
Hope that's helpful!
Chris