By mriester on
hi!
now, i have a members area with htaccess and static html pages. in the area, there are a few perl cgis. i'd like to switch to drupal, but i need this cgis and i don't want the users type in there password twice. is there already some perl code for finding out, if a user is logged in? or is this easy to find out?
markus
Comments
Anyone? I'm in this exact
Anyone? I'm in this exact situation--trying to transition from a framed, htaccess perl site to drupal. There are some perl scripts I don't want to have to re-write in php just yet. Is there a way to tell in a perl script if someone is logged in as a certain role to drupal? If not, is there a way to run the perl scripts from inside drupal somehow?
Three and a half years later, another seeks similiar solution
I find myself in a similiar situation. I have a site hosted on drupal, to which I'm adding some Perl based cgi scripts. I'm seeking similiar advise to what the two folks who have posted previously to this thread have asked.
Here is what I've figured out so far:
In perl I generally use CGI::Session::Auth::DBI in perl development to handle user authentication / authorization issues. That module depends on these tables: auth_user, auth_group, groups and sessions.
In drupal, similiar functionality is provided by the interaction between these tables: sessions, role, users, users_roles.
At this moment, it seems that my best bet might be to create my application users through the perl code which then invokes the drupal API to create parallel users and parallel sessions in the drupal schema, deleting that session, when they log out from the perl scripts.
But what seems ideal in my mind would be to have a new module along the lines of CGI::Session::Auth::DBI::Drupal which would permit my perl scripts to interact directly with the drupal schema and avoid all the duplication in the database backend.
I would certainly appreciate some collaboration on developing such a solution from anyone else who has a similar itch to scratch. Please contact me if you would want to help with such a project.
Thanks,
-- Hugh Esco
and four years later, coming back to this question again . . .
I have not yet taken the time to test this in a real world application
(though I expect to soon do so). But in the mean time, I'm guessing
that something like this just might work:
First create a drupal <-> perl application glue module,
use it to expose hook_permissions for your perl application.
For guidance, see this:
http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...
For ideas on using the drupal user, roles and session in perl:
http://search.cpan.org/~geewiz/CGI-Session-Auth-1.07/Auth/DBI.pm
http://search.cpan.org/~markstos/CGI-Session-4.48/lib/CGI/Session/Driver...
But essentially it will look like this:
use CGI;
use CGI::Session;
use CGI::Session::Driver::DBI;
use CGI::Session::Auth::DBI;
my $cgi = new CGI;
my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});
$s = CGI::Session->new('driver:mysql', undef,
{
DataSource => 'dbi:mysql:host=localhost,database=drupal_db',
TableName => 'drpl_sessions',
IdColName => 'sid',
DataColName => 'session',
});
my $auth = new CGI::Session::Auth::DBI({
CGI => $cgi,
Session => $s,
DSN => 'dbi:mysql:host=localhost,database=drupal_db',
DBUser => 'drupal_user',
DBPasswd => 'secret',
UserTable => 'drpl_users',
UserIDField => 'uid',
UsernameField => 'name',
PasswordField => 'pass',
GroupTable => 'drpl_users_roles',
GroupField => 'rid',
GroupUserIDField => 'uid',
});
$auth->authenticate();
if ($auth->loggedIn) {
showSecretPage;
}
else {
showLoginPage;
}