######### # Author: rmp # Last Modified: $Date: 2009-08-03 00:05:09 +0100 (Mon, 03 Aug 2009) $ # Id: $Id: authdecor.pm 339 2009-08-02 23:05:09Z zerojinx $ # Source: $Source$ # $HeadURL: https://clearpress.svn.sourceforge.net/svnroot/clearpress/branches/prerelease-1.26/lib/ClearPress/authdecor.pm $ # package ClearPress::authdecor; use strict; use warnings; use base qw(ClearPress::decorator Exporter); use ClearPress::authenticator::session; use Readonly; our $VERSION = do { my ($r) = q$Revision: 339 $ =~ /(\d+)/smx; $r; }; Readonly::Scalar our $DOMAIN => 'mysite.com'; Readonly::Scalar our $AUTH_COOKIE => 'mysite_sso'; Readonly::Array our @EXPORT_OK => qw($AUTH_COOKIE); sub new { my ($class, @args) = @_; my $self = $class->SUPER::new(@args); $self->{title} = 'My Site'; $self->{stylesheet} = [qw(/css/mysite.css)]; $self->{meta_author} = q$Author: zerojinx $; if(!ref $self->{jsfile}) { $self->{jsfile} = []; } unshift @{$self->{jsfile}}, qw(/js/jquery-1.3.2.min.js); return $self; } sub username { my ($self, $username) = @_; if(defined $username) { $self->{username} = $username; } if(defined $self->{username}) { return $self->{username}; } my $auth = ClearPress::authenticator::session->new(); my $cgi = $self->cgi(); my $cookie = $cgi->cookie($AUTH_COOKIE); if(!$cookie) { ######### # no auth cookie. don't bother trying to decrypt # return; } my $ref = $auth->authen_token($cookie); if(!$ref) { ######### # Failed to authenticate session token # return; } return $ref->{username}; } sub linkbucket { my $self = shift; my $authenticated = $self->username()?1:0; ######### # un/authenticated stuff # my $defaults = [ $authenticated ? {'Logout' => '/logout'} : {'Login' => '/login'}, ]; ######### # standard links # my $standard = [ {'Home' => q[/]}, ]; ######### # session-based (user-defined) links # my $session = []; return [@{$defaults}, @{$standard}, @{$session}]; } sub site_header { my ($self, @args) = @_; my $header = $self->SUPER::site_header(@args); $header .= q[

@{[$self->site_login_form]}
\n]; return $header.q[
]; } sub footer { return q[
]; } sub site_login_form { my $host = $ENV{HTTP_X_FORWARDED_HOST} || $ENV{HTTP_HOST} || q[]; if($host) { $host = "https://$host"; } return qq[

]; } 1; __END__ =head1 NAME ClearPress::authdecor =head1 VERSION $LastChangedRevision: 339 $ =head1 SYNOPSIS =head1 DESCRIPTION =head1 SUBROUTINES/METHODS =head2 new - constructor, overridden from superclass but calls up. Present here to set default page attributes like title, stylesheet etc. my $oDecor = ClearPress::decor->new(); =head2 username - overridden from superclass - fetch username of authenticated user from LDAP or session my $sUsername = $oDecor->username(); =head2 linkbucket - data structure containing default links. TODO: examine user session my $arLinkHash = $oDecor->linkbucket(); Structure is: [ { Name => href }, { Name => href }, { Name => href }, { Name => href }, ] =head2 site_header - overridden from superclass. Tacks the linkbucket on to the default header my $sSiteHeaderHTML = $oDecor->site_header(); =head2 footer - overridden from superclass. Closes div#main my $sSiteFooterHTML = $oDecor->footer(); =head2 site_login_form - authentication form used for popup and cgi-bin/login my $sSiteLoginHTML = $oDecor->site_login_form(); =head1 DIAGNOSTICS =head1 CONFIGURATION AND ENVIRONMENT =head1 DEPENDENCIES =over =item strict =item warnings =item Readonly =item ClearPress::authenticator::session =item ClearPress::decorator =item Exporter =back =head1 INCOMPATIBILITIES =head1 BUGS AND LIMITATIONS =head1 AUTHOR $Author: Roger Pettett$ =head1 LICENSE AND COPYRIGHT This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . =cut