Gossamer Forum
Home : Products : Gossamer Links : Discussions :

use user data of one links for another

Quote Reply
use user data of one links for another
Hi,

I had this topic quite a while ago. I would like to use several Links installations on one server with one Login (not Community).
I thought it would be a good and easy going idea to PRE and POST change database anytime user data is accessed.

Code:
$mgr->install_hooks('ONEUSERDB', [['user_login', 'PRE', 'Plugins::ONEUSERDB::user_login', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_signup', 'PRE', 'Plugins::ONEUSERDB::user_signup', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_validate', 'PRE', 'Plugins::ONEUSERDB::user_validate', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_validate_email', 'PRE', 'Plugins::ONEUSERDB::user_validate_email', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_pass_email', 'PRE', 'Plugins::ONEUSERDB::user_pass_email', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_valid_user', 'PRE', 'Plugins::ONEUSERDB::auth_valid_user', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_get_pass', 'PRE', 'Plugins::ONEUSERDB::auth_get_pass', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_get_user', 'PRE', 'Plugins::ONEUSERDB::auth_get_user', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_valid_session', 'PRE', 'Plugins::ONEUSERDB::auth_valid_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_create_session', 'PRE', 'Plugins::ONEUSERDB::auth_create_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_delete_session', 'PRE', 'Plugins::ONEUSERDB::auth_delete_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['init_user', 'PRE', 'Plugins::ONEUSERDB::init_user', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_login', 'POST', 'Plugins::ONEUSERDB::post_user_login', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_signup', 'POST', 'Plugins::ONEUSERDB::post_user_signup', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_validate', 'POST', 'Plugins::ONEUSERDB::post_user_validate', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_validate_email', 'POST', 'Plugins::ONEUSERDB::post_user_validate_email', '']]);
$mgr->install_hooks('ONEUSERDB', [['user_pass_email', 'POST', 'Plugins::ONEUSERDB::post_user_pass_email', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_valid_user', 'POST', 'Plugins::ONEUSERDB::post_auth_valid_user', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_get_pass', 'POST', 'Plugins::ONEUSERDB::post_auth_get_pass', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_get_user', 'POST', 'Plugins::ONEUSERDB::auth_get_user', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_valid_session', 'POST', 'Plugins::ONEUSERDB::post_auth_valid_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_create_session', 'POST', 'Plugins::ONEUSERDB::post_auth_create_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['auth_delete_session', 'POST', 'Plugins::ONEUSERDB::post_auth_delete_session', '']]);
$mgr->install_hooks('ONEUSERDB', [['init_user', 'POST', 'Plugins::ONEUSERDB::post_init_user', '']]);

Where there is the following in ONEUSERDB:

Code:
# Your code begins here.
use GT::SQL;
my $ONEUSERDB = GT::SQL->new({def_path => '/path_to_oneuserdb/cgi-bin/admin/defs',cache => 1});
my $REGULARDB = GT::SQL->new({def_path => '/path_to_regular/cgi-bin/admin/defs',cache => 1});

And for any of the above subroutines:

Code:
sub user_login {
$DB = $ONEUSERDB;
return;
}
sub post_user_login {
$DB = $REGULARDB;
return;
}

Registration works fine, validation with login seems to work but if a User logs in with his Username and Pass it won´t work.
It leads to:
Quote:
You must first login before you can access that.

Maybe somebody has a more elegant way than I have and is willing to share it or someone can give me a hint where I have a mistke.

Thank you

Niko
Quote Reply
Re: [el noe] use user data of one links for another In reply to
Hi,

to add some more information:
I have just seen, that in POST hook in the above code I had auth_get_user instead of post_auth_get_user. I changed that but the problem remains.
I dont´t want users to jump from one to another domain if he is logged in.
I only want to have one User table for all projects. There is no interaction between the sites.

After playing around it looks like the problem lies somewhere in the setting of the session cookie.
In Authenticate.pm in auth_create_session there is

Code:
# Now redirect to another URL and set cookies, or set URL string.
my $url = $IN->param('url');
my $redirect = 0;
if ($CFG->{user_sessions} eq 'Cookies') {
my $session_cookie = $IN->cookie(
-name => $CFG->{user_cookie_prefix} . 's',
-value => $session_id,
-path => '/',
-domain => $CFG->{user_cookie_domain},
-expires => ($remember ? '+10y' : '')
);
if ($url) {
print $IN->redirect(-force => 1, -cookie => [$session_cookie], -url => $url);
$redirect = 1;
}
else {
print $IN->header(-force => 1, -cookie => [$session_cookie]);
}

If a user tries to login with a url the login seems to work whereas the login without url and redirect won´t work.

Thanks

Niko

Last edited by:

el noe: Feb 18, 2009, 11:26 PM
Quote Reply
Re: [el noe] use user data of one links for another In reply to
Blush it works now and I don´t know why - anyway I am happy because it works.

Regards

Niko