Gossamer Forum
Home : Products : Gossamer Links : Discussions :

UPDATED: Current user plugin 1.01

Quote Reply
UPDATED: Current user plugin 1.01
UPDATE: Version 1.01 now online

Fixed:

- During install, libary path is now picked up from Links config.
- During install, perl path now pick up from Links config.
- Better error handling if there are problems installation.

Updated:

userlookup.cgi - Cleaned up code. Removed anything that wasn't needed.

Download UserLook 1.01 Plugin: http://www.netmall.net/UserLookup.tar

Special thanks to Alex for assistance with the not yet so documented plugin installation routines (and for Links SQL NG in general!).

I found this to be a handy little plugin to allow you to call (via SSI) the currently authenticated Links user. If the user is not logged in, it returns "Guest", otherwise it returns their Name.

The plugin will automatically install into your user cgi directory. After installing the plugin, you can access it via SSI with a command in your static pages or templates like:



Well it looks like my SSI call is being edited out by the forum... But you need to do an SSI exec cgi of the user-lookup.cgi program.

You can download the plugin from here:

http://www.netmall.net/UserLookup.tar

I'm very interested to hear how this works for everyone. Please share your feedback.

Enjoy,

AlexJ

Quote Reply
Re: Current user plugin In reply to
Hi,

I tried it out and there where a few problems, mainly in the installation. A quick comment on the code in user-lookup.cgi. You use'd GT::CGI and created a GT::CGI object. This isn't required. In fact all you need to do is:

use Links qw/$DB $IN $USER/;

and $IN is your CGI object. So then do:

print $IN->header;
if ($USER) {
..
}

Also, to make it work on everyones system, you need to alter the use lib '..' to set the path to the links sql admin directory. To do this, and to add some error checking, your install should look like:

Code:
sub install {
my ($mgr, $tar) = @_;
my $file = $tar->get_file ('user-lookup.cgi');
my $code = $file->body_as_string;
$code =~ s/use lib '[^']+'/use lib '$CFG->{admin_root_path}'/;
$file->body ($code);
$file->name ( $CFG->{build_root_path} . '/user-lookup.cgi');
unless ($file->write) {
$Plugins::UserLookup::error = "Unable to save user-lookup.cgi to your user directory, please set permissions. Error: $GT::Tar::error";
return;
}
return "Plugin installed successfully.";
}
I did find a few bug in the plugin manager that prevent the error from getting reported properly, but I'll fix that up in the final.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Current user plugin In reply to
Alex,

Thanks for taking the time to test it out... and for the great comments and code additions for the install routine...

With what you said in mind... I also need to set the path to perl during the install to make it just plug right in.....Right?

Thanks,

AlexJ

Quote Reply
Re: Current user plugin In reply to
This routine includes getting the correct path to the users libs and perl:

Code:
my $file = $tar->get_file ('user-lookup.cgi');
my $code = $file->body_as_string;
$code =~ s,^(#!)[^\n]+,$1$CFG->{path_to_perl},;
$code =~ s/use lib '[^']+'/use lib '$CFG->{admin_root_path}'/;
$file->body ($code);
$file->name ( $CFG->{build_root_path} . '/user-lookup.cgi');
unless ($file->write) {
$Plugins::UserLookup::error = "Unable to save user-lookup.cgi to your user directory, please set permissions. Error: $GT::Tar::error";
return;
}
chmod (0755, "$CFG->{build_root_path}/user-lookup.cgi");

return "The plugin has been successfully installed!";
Does that look about right?

I can't wait for the full docs on this....!

Thanks,

AlexJ