Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Block all but registered users from clicking links?

Quote Reply
Block all but registered users from clicking links?
Hello,
What coding can I put into the templates that would prevent non registered users from clicking on links?

For example we offer downloads, so I have a link that says, "Download Content Now". I want registered users to see this and be able to click on it, but if a user is not logged in then I want them to just see "You need to register to download this item".

I've got the first part, which was easy enough and anyone can download the content, but havnt figured out how to block the download link if the users is not logged in.

Thanks,
Quote Reply
Re: [kamidan] Block all but registered users from clicking links? In reply to
using the Plugin creator, create a plugin that uses a PRE hook on "handle_jump".

the subroutine in the plugin module should look something like:

Code:
sub pre_handle_jump {
if ($USER) {
return @_;
} else {
$PLG->action(STOP);
print $IN->header();
print Links::SiteHTML::display("error", { error => "You must log in to use this feature." });
}
}

not tested, but I'm pretty sure that will do it.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Block all but registered users from clicking links? In reply to
You've thoroughly confused me (which is not hard to do by the way Blush )

Im guessing that since this link is going to be on a static page (the contents detail page) then we can't use something simple like <%if user%> download content <%else%>login to download this content <%endif%>

So after creating this plugin and installing it, how do I actually use it? Will it just change any clickable link in our templates to tell the user the error message if they are not logged in?

Last edited by:

kamidan: Aug 16, 2006, 2:53 AM
Quote Reply
Re: [kamidan] Block all but registered users from clicking links? In reply to
You don't need to do anything in your templates. Just let jump.cgi do it's thing. If a user isn't logged in, they'll get an error page when they click the link.

I'll try to get you a full plugin written up for you after work today.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Block all but registered users from clicking links? In reply to
Okay,
I tried it, but perhaps I didnt do it right because when Im not logged in, I can still access the link and I dont get the error message.

Im using jump.cgi to access the link
Code:
jump.cgi?ID=4&view=content




I packaged up what you wrote as a pre plugin and installed it. and I am using the jump.cgi

There is an error though in the plugins pm file such as this:
Number found where operator expected at LoginB4Download.pm line 45, near "1" (Missing semicolon on previous line?) syntax error at LoginB4Download.pm line 45, near "1" LoginB4Download.pm had compilation errors.


And heres what i pasted in.
Code:

sub pre_handle_jump
{ if ($USER) { return @_;
} else {
$PLG->action(STOP);
print $IN->header();
print Links::SiteHTML::display("error", { error => "Please Login to download this file." }); } }



And when I view the plugins edit after installing, it is showing this that I chose handle_jump and PRE:
handle_jump (PRE)

Last edited by:

kamidan: Aug 16, 2006, 10:41 AM
Quote Reply
Re: [kamidan] Block all but registered users from clicking links? In reply to
See attachment. Let me know if you have any problems.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Block all but registered users from clicking links? In reply to
Thank you, that works perfect and I've managed to learn a bit more as I see where I went wrong.

Thanks again,