Gossamer Forum
Home : Products : Others : Gossamer Community :

GEtting user variables, and standard user details into new script

Quote Reply
GEtting user variables, and standard user details into new script
Hi,

I wish you had $USER in GComm - would make it a lot easier to write stand alone scripts :P

I currently have the following code:

Code:
#!/usr/bin/perl5
# ==================================================================
# Gossamer Community
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# CVS Info :
# NAme : birthdays.cgi
#
# Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

use strict;
use CGI::Carp qw(fatalsToBrowser);
use lib '/home/user/site.com/secure_data/lib';
use Community qw/comm_init comm_config comm_fatal $DB $IN $CFG/;
use GT::CGI;
use GT::Date;
use CGI::Carp qw(fatalsToBrowser);
use Carp;
require Community::Web::User;

local $SIG{__DIE__} = \&fatal;

Community::init('/home/user/site.com/secure_data');

print $IN->header();

GT::Template->parse_print("$CFG->{path_private}/templates/$CFG->{system_template_set}/message_home.html", { %$CFG }, { compress => 0 });

However, if someone is logged in - I want to have their details too (i.e username, etc).

It seems that using:

Code:
use Community qw/comm_init comm_config comm_fatal $DB $IN $CFG $USER/;

..doesn't work , as I get an error about $USER not being an exportable variable.

TIA for any suggestions.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] GEtting user variables, and standard user details into new script In reply to
Andy this is from /lib/Community/Web/User.pm and it prints user home, I'm afraid there is no $USER variable exported

Code:
# Check if the user already has a valid session.
if ($IN->cookie($CFG->{session_cookie_name_session})) {
my $user = comm_auth(
session => $IN->cookie($CFG->{session_cookie_name_session}),
ip => $ENV{REMOTE_ADDR}
);
if ($user) {
# If the user has a valid session for another account, let's log that other session out
# to make sure the apps don't authenticate the user as the wrong account.
if (lc $user ne $username) {
require Community::User;
push @$cookies, Community::User::cuser_logout($user);
}
else {
$user->{action} = 'login';
return ('user_home.html', $user);
}
}
}

And this is a download script for some documents that are available only to our clients.

Code:
#!/usr/bin/perl
#------------------------------------------------------------------------------

use lib '/path/to/login/lib';

use GT::CGI;
use Community qw/
comm_init
comm_config
comm_auth
comm_login_url/;

comm_init('/path/to/login');

my $IN = new GT::CGI;
my $return = "https://www.domain.com";
$return =~ s|/?$|/download.cgi?|;
$return .= $IN->query_string;
my $url = comm_login_url(return_to => $return);


my $session = $IN->cookie('Passport_Sesssion');
$session ||= $IN->param('Passport_Sesssion');

if (! $session) {
print $IN->redirect( $url ) and exit;
}

my $user = comm_auth (session => $session );
#if (! $user or $user->{app_Billing} != 2) {
if (! $user) {
print $IN->redirect( $url ) and exit;
}
else {
# Download code
}
Hope this helps.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] GEtting user variables, and standard user details into new script In reply to
Hi,

Thanks for the reply. I've ended up taking the GLinks route, as it can just as easily be integrated into GComm, as doing it in GComm itself. Shame GComm isn't very user friendly in terms of having separate scripts and whatnot :(

Thanks for the reply though.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!