Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

new file user login required...

Quote Reply
new file user login required...
I'm creating an external cgi file to do certain things in links that I don't want a user to be able to access without logging in first.

How do I use the linksSQL pre-writing user modules at the top of my perl file so that a user can't access the program without logging in first?


Here is what I have...

Code:

#!/usr/bin/perl
#================================
use strict;
use lib 'my path...';

use Links::SiteHTML;
Links::init('my path...');
Links::init_user();
local $SIG{__DIE__} = \&Links::fatal;
main();

sub main {
#---------------------------------------------------
#

if (!$USER) {

# redirect to the login page...

}

else {

# run my sub routine...

}

}


The problem is that even when I am not logged in, it will detect the $USER as existing...

according to modify.pm, add.pm etc, it uses this snip of code...

Code:

if ($CFG->{user_required} and ! $USER) {
print $IN->redirect( Links::redirect_login_url('add') );
return;
}


I don't need to define the file as user_required and edit anything complicated, I just want it to simply redirect to the login page if not logged in...

Any suggestions would be appreciated,

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
You also need a:
use Links qw/$USER/;

Adrian
Quote Reply
Re: [brewt] new file user login required... In reply to
Wow, thanks, I think that fixed the problem...

I had edited my code a little when I pasted it, but doesn't

Quote:
use Links qw/:objects/;


include the $USER?

I originally had that in my header also when I was testing it...?

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
Yup, it includes: $IN $CFG $DB $USER VIEWABLE

Adrian
Quote Reply
Re: [brewt] new file user login required... In reply to
Thanks... I'm about to post the file I was writing... (my_image)...

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
From how I read this, it sounds like I'm trying to do the same thing: I want a page that only registered members can access. If they're not signed in, it will bump them to a login/signup page. (I have read what is mentioned here, but still don't get it -- what file is even being edited here?)

How can I create a page that's viewable only for logged in users, and ideally edit the portion the registered member sees in the templates section? (Like you can edit the content/wording of search pages, add pages, etc.) I had some marginal success going in this direction by coping add.cgi and renaming it -- but since I don't want people to add links, that didn't get me too far.

Any help would be hugely appreciated! I'm not too tech-savvy, so feel free to dumb it down. (For the most part, I can parrot stuff, but don't really get what I'm doing.) Thanks!
Quote Reply
Re: [SKN] new file user login required... In reply to
It obviously depends on the script you are creating!

I use something like this when I create a new script:
Code:

#!/usr/bin/perl
#================================
use strict;
use lib 'your admin path';
use Links qw/:objects/; # or whatever $IN, $DB, $CFG, $USER etc...
use Links::SiteHTML; # if your using templates
use GT::Mail; # if your sending mail...
Links::init('your admin path');
Links::init_user(); # gets the user information

local $SIG{__DIE__} = \&Links::fatal;
main();
sub main {
#---------------------------------------------------
#
my $do = $IN->param('do'); # gets input

# check to see if your logged in
if (!$USER) {
print $IN->redirect('$CFG->{db_cgi_url}/user.cgi?url=path to this filename');

}

# the rest of your script...

}


Hope this helps,

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
Hi, and thanks so much for the reply! :D I don't really need it to be a script that does anything other than auth the user. It's essentially allowing the user access to content on an inside page -- and only members/registered users can access it. Does that make sense?

- Nancy
Quote Reply
Re: [SKN] new file user login required... In reply to
In Reply To:
I don't really need it to be a script that does anything other than auth the user.[/quote]
That is what user.cgi already does...

In Reply To:

It's essentially allowing the user access to content on an inside page -- and only members/registered users can access it. Does that make sense?[/quote]
Honestly, No. Are you talking about an html page? If you want to have user access to a regular html page, you are going to have to make it into a script, or password protect the folder it is in.


To user protect an html page, you could use php or ssi maybe... I'm not exactly sure what your talking about.

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
Hi, again, and sorry for being so confusing. I just want to be able to add several pages of plain old HTML content to this section using the existing user login info (not a separate htaccess request or anything).

It's actually a super-basic thing I'm shooting for, and I'm just stupid enough to not have a clue as to go about doing it properly. I would imagine I need to make a cgi page -- but I'm lost as to how to make that works so it displays the content I want. (All sorts of other bits and pieces are called from scripts like add.cgi and I don't know what to do with them.)

Ideally, I want to create the meat of the page in the standard templates section, not always needing to alter a script every time I want to change a word here and there. So if I can create a script that can call a page from the templates section after making sure they're logged in, that is what I would prefer... but I could just make it in script format if need be.

The idea is that if they sign up for the site, they get access to a suite of cool articles and features -- though I want to make it super-simple for the end user. One login, then they can access many pages. But if you're not logged in, you get bumped to the "you must be logged in to access that page" page.

Again, my apologies for not being clear. I'm an editor, not terribly tech-minded, but in this role by default. ;-) Thanks for your help!

Last edited by:

SKN: Jan 28, 2005, 4:27 PM
Quote Reply
Re: [SKN] new file user login required... In reply to
If you have php installed you can do something like this to all of your html files.

At the top of each file, put this:

Code:

<?
$login_path = "";
if (empty($HTTP_COOKIE_VARS["s"])) {
header('Location: ' . $login_path );

return;
}
?>


Of course edit your path. If you have Community installed, the setup cookie name will be Community_Name or under Setup -> User Sessions...


Hope this helps,

- Jonathan
Quote Reply
Re: [SKN] new file user login required... In reply to
The PageBuilder plugin allows you to add any number of pages. You can configure each page separately, and one of the things you can do is set access permissions (all, only logged in users, only admins, only editors).

I hope this helps.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] new file user login required... In reply to
Thank you both for your help and suggestions! I very much appreciate your time. I will see what I can figure out. :-)

- Nancy
Quote Reply
Re: [yogi] new file user login required... In reply to
Just curious, using your PageBuilder plugin, how do you set access permissions on your build files? SSI Includes? PHP Includes?


Curiousity killed the cat, but the cat had 9 lives...

- Jonathan
Quote Reply
Re: [jdgamble] new file user login required... In reply to
With PageBuilder, you can - on a per page basis - control access to dynamic pages, not to static pages. It just saves you the hassle of writing your own cgi script.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [jdgamble] new file user login required... In reply to
jdgamble wrote:
It obviously depends on the script you are creating!

I use something like this when I create a new script:
Code:


#!/usr/bin/perl
#================================
use strict;
use lib 'your admin path';
use Links qw/:objects/; # or whatever $IN, $DB, $CFG, $USER etc...
use Links::SiteHTML; # if your using templates
use GT::Mail; # if your sending mail...
Links::init('your admin path');
Links::init_user(); # gets the user information

local $SIG{__DIE__} = \&Links::fatal;
main();
sub main {
#---------------------------------------------------
#
my $do = $IN->param('do'); # gets input

# check to see if your logged in
if (!$USER) {
print $IN->redirect('$CFG->{db_cgi_url}/user.cgi?url=path to this filename');

}

# the rest of your script...

}



Hope this helps,