Revision 136 (by dpavlin, 2006/03/19 20:57:08) better example for integration with Strix
#!/usr/bin/perl -w

use strict;
use lib './lib';
use Webnote;
use PHP::Session;
use Data::Dumper;

my $wn = new Webnote(
	dsn => 'dbi:Pg:dbname=strix',
	db_user => 'web',
	db_passwd => '',
	db_codepage => 'ISO-8859-2',
	adminEmail => 'nobody@localhost',
	debug => 0,
);

my $session_name = 'PLIVAweb';

$wn->run( default => sub {
	my $self = shift;

	my $cgi = $wn->{'cgi'} || die "no cgi?";
	if (my $cookie = $cgi->cookie( $session_name )) {
		my $session = PHP::Session->new($cookie);
		my $nick = $session->get('_s_pod')->{'nick'} ||
			die "can't find nick!";
		my $sth = $self->{'dbh'}->prepare(qq{
			select UserCanDoOnObject(?, 'PERM_WRITE', 'kats', ?)
		}) || die $self->{'dbh'}->errstr();
		$sth->execute(
			$session->get('_s_pod')->{'uid'},
			$session->get('_s_pod')->{'kid'},
		) || die $sth->errstr();
	
		my ($access_ok) = $sth->fetchrow_array;
	
		if ($access_ok) {
			$self->load($nick);
		} else  {
			print $cgi->header,
			"You need to be logged in to access this resource";
		}
	} else {
		print $cgi->header,
			"can't find session cookie $session_name";
	}
	return 1;
} );