######### # 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[