Merge branch 'Varless' into WebGUI8

This commit is contained in:
Colin Kuskie 2010-11-18 11:04:42 -08:00
commit dcff137cfa
62 changed files with 476 additions and 650 deletions

View file

@ -754,7 +754,7 @@ sub www_view {
$var->{backToSiteUrl} = $url->page;
# temporary! We are now in admin mode!
$session->var->switchAdminOn;
$session->switchAdminOn;
# Add vars for AdminBar
$var->{adminPlugins} = $self->getAdminPluginTemplateVars;

View file

@ -454,7 +454,7 @@ The missing URL.
sub addMissing {
my $self = shift;
my $assetUrl = shift;
return undef unless ($self->session->var->isAdminOn);
return undef unless ($self->session->isAdminOn);
my $i18n = WebGUI::International->new($self->session, "Asset");
my $output = $i18n->get("missing page query");
$output .= '<ul>
@ -592,14 +592,15 @@ to SSL.
sub checkView {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
my ($conf, $var, $http) = $self->session->quick(qw(config var http));
my $session = $self->session;
my ($conf, $http) = $self->session->quick(qw(config http));
if ($conf->get("sslEnabled") && $self->get("encryptPage") && ! $self->session->request->secure) {
# getUrl already changes url to https if 'encryptPage'
$http->setRedirect($self->getUrl);
$http->sendHeader;
return "chunked";
}
elsif ($var->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash
elsif ($session->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash
my $queryFrag = "func=manageTrash";
if ($self->session->form->process('revision')) {
$queryFrag .= ";revision=".$self->session->form->process('revision');
@ -608,7 +609,7 @@ sub checkView {
$http->sendHeader;
return "chunked";
}
elsif ($var->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard
elsif ($session->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard
my $queryFrag = "func=manageClipboard";
if ($self->session->form->process('revision')) {
$queryFrag .= ";revision=".$self->session->form->process('revision');
@ -679,7 +680,7 @@ sub dispatch {
my $session = $self->session;
my $state = $self->get('state');
##Only allow interaction with assets in certain states
return if $state ne 'published' && $state ne 'archived' && !$session->var->isAdminOn;
return if $state ne 'published' && $state ne 'archived' && !$session->isAdminOn;
my $func = $session->form->param('func') || 'view';
my $viewing = $func eq 'view' ? 1 : 0;
my $sub = $self->can('www_'.$func);
@ -1594,7 +1595,7 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
sub getToolbar {
my $self = shift;
return undef unless $self->canEdit && $self->session->var->isAdminOn;
return undef unless $self->canEdit && $self->session->isAdminOn;
return $self->{_toolbar}
if (exists $self->{_toolbar});
my $userUiLevel = $self->session->user->profileField("uiLevel");
@ -2372,7 +2373,7 @@ sub processTemplate {
}
if (! Exception::Class->caught() ) {
$var = { %{ $var }, %{ $self->getMetaDataAsTemplateVariables } };
$var->{'controls'} = $self->getToolbar if $session->var->isAdminOn;
$var->{'controls'} = $self->getToolbar if $session->isAdminOn;
$var->{'assetIdHex'} = $session->id->toHex($self->getId);
my %vars = (
%{$self->get},
@ -2683,7 +2684,7 @@ The default view method for any asset that doesn't define one. Under all normal
sub view {
my $self = shift;
if ($self->session->var->isAdminOn) {
if ($self->session->isAdminOn) {
return $self->getToolbar.' '.$self->getTitle;
} else {
return "";

View file

@ -564,7 +564,7 @@ Generate the view method for the Asset, and handle caching.
sub view {
my $self = shift;
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
if (!$self->session->isAdminOn && $self->get("cacheTimeout") > 10) {
my $out = $self->session->cache->get($self->getViewCacheKey);
return $out if $out;
}
@ -574,7 +574,7 @@ sub view {
$var{fileIcon} = $self->getFileIconUrl;
$var{fileSize} = Number::Format::format_bytes($self->get("assetSize"));
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) {
if (!$self->session->isAdminOn && $self->get("cacheTimeout") > 10) {
$self->session->cache->set($self->getViewCacheKey, $out, $self->get("cacheTimeout"));
}
return $out;

View file

@ -210,7 +210,7 @@ sub view {
my $session = $self->session;
my $cache = $session->cache;
my $cacheKey = $self->getWwwCacheKey('view');
if (!$session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$session->isAdminOn && $self->cacheTimeout > 10) {
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@ -233,7 +233,7 @@ sub view {
$var{annotateJs} = $crop_js . $domMe;
$var{parameters} .= sprintf(q{ id="%s"}, $self->getId);
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$session->isAdminOn && $self->cacheTimeout > 10) {
$cache->set( $cacheKey, $out, $self->get("cacheTimeout") );
}
return $out;

View file

@ -209,7 +209,7 @@ sub view {
my $self = shift;
my $cache = $self->session->cache;
my $cacheKey = $self->getWwwCacheKey('view');
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@ -232,7 +232,7 @@ sub view {
$var{noInitialPage} = $i18n->get('noInitialPage');
$var{noFileSpecified} = $i18n->get('noFileSpecified');
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
$cache->set( $cacheKey, $out, $self->cacheTimeout);
}
return $out;
@ -268,7 +268,7 @@ Web facing method which is the default view page. This method does a
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
if ($self->session->var->isAdminOn) {
if ($self->session->isAdminOn) {
return $self->session->asset($self->getContainer)->www_view;
}
$self->session->http->setRedirect($self->getFileUrl($self->showPage));

View file

@ -99,7 +99,7 @@ Display the redirect url when in admin mode.
sub view {
my $self = shift;
if ($self->session->var->isAdminOn) {
if ($self->session->isAdminOn) {
return $self->getToolbar.' '.$self->getTitle.' '.$self->redirectUrl;
}
else {
@ -121,7 +121,7 @@ sub www_view {
my $i18n = WebGUI::International->new($self->session, "Asset_Redirect");
my $url = $self->redirectUrl;
WebGUI::Macro::process($self->session, \$url);
if ($self->session->var->isAdminOn() && $self->canEdit) {
if ($self->session->isAdminOn() && $self->canEdit) {
return $self->getAdminConsole->render($i18n->get("what do you want to do with this redirect").'
<ul>
<li><a href="'.$url.'">'.$i18n->get("go to the redirect url").'</a></li>

View file

@ -239,7 +239,7 @@ Shortcut that the Visitor would see, or their own.
sub discernUserId {
my $self = shift;
return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
return ($self->canManage && $self->session->isAdminOn) ? '1' : $self->session->user->userId;
}
#-------------------------------------------------------------------
@ -464,7 +464,7 @@ admin mode is on.
sub _overridesCacheTag {
my $self = shift;
#cache by userId, assetId of this shortcut, and whether adminMode is on or not.
return ["shortcutOverrides", $self->getId, $self->session->user->userId, $self->session->var->isAdminOn];
return ["shortcutOverrides", $self->getId, $self->session->user->userId, $self->session->isAdminOn];
}
#-------------------------------------------------------------------
@ -488,7 +488,7 @@ sub getOverrides {
my $overridesRef = $cache->get($self->_overridesCacheTag);
##If admin mode is not on, and the cache is valid, and not expired, and the user object was not updated,
##return the cached value.
if ( ! $session->var->isAdminOn
if ( ! $session->isAdminOn
&& $overridesRef
&& $overridesRef->{cacheNotExpired}
&& $overridesRef->{userLastUpdated} >= $u->get('lastUpdated')) {
@ -591,7 +591,7 @@ sub getShortcutByCriteria {
if ($assetId) {
$scratchId = "Shortcut_" . $assetId;
if($self->session->scratch->get($scratchId) && !$self->disableContentLock) {
unless ($self->session->var->isAdminOn) {
unless ($self->session->isAdminOn) {
return WebGUI::Asset->newById($self->session, $self->session->scratch->get($scratchId));
}
}
@ -990,8 +990,8 @@ sub www_getUserPrefsForm {
my @fielden = $self->getPrefFieldsToShow;
my $f = WebGUI::HTMLForm->new($self->session,extras=>' onsubmit="submitForm(this,\''.$self->getId.'\',\''.$self->getUrl.'\');return false;"');
$f->raw('<table cellspacing="0" cellpadding="3" border="0">');
my $allowedToSave = ( ! $session->var->isAdminOn && $self->getParent->canPersonalize )
|| ( $session->var->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
my $allowedToSave = ( ! $session->isAdminOn && $self->getParent->canPersonalize )
|| ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
if ($allowedToSave) {
$f->hidden(
-name => 'func',
@ -1090,7 +1090,7 @@ sub www_saveUserPrefs {
my $self = shift;
my $session = $self->session;
return '' unless $self->getParent->canPersonalize
|| ( $session->var->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
|| ( $session->isAdminOn && $session->user->isInGroup($session->setting->get('groupIdAdminUser')) );
my @fellowFields = $self->getPrefFieldsToShow;
my %data = ();
$self->uncacheOverrides;

View file

@ -1654,7 +1654,7 @@ sub view {
my $session = $self->session;
my $cache = $session->cache;
my $cacheKey = $self->getWwwCacheKey( 'view' );
if (!$session->var->isAdminOn && $self->get("cacheTimeout") > 10){
if (!$session->isAdminOn && $self->get("cacheTimeout") > 10){
my $out = $cache->get( $cacheKey );
return $out if $out;
}
@ -1856,7 +1856,7 @@ sub view {
$var{continueShoppingUrl} = $self->getUrl;
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && $self->{_hasAddedToCart} != 1){
if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && $self->{_hasAddedToCart} != 1){
$cache->set( $cacheKey, $out, $self->cacheTimeout );
}
return $out;

View file

@ -253,7 +253,7 @@ sub view {
my $session = $self->session;
my $versionTag = WebGUI::VersionTag->getWorking($session, 1);
my $noCache =
$session->var->isAdminOn
$session->isAdminOn
|| $self->cacheTimeout <= 10
|| ($versionTag && $versionTag->getId eq $self->tagId);
my $cacheKey = $self->getWwwCacheKey('view', $calledAsWebMethod);
@ -265,7 +265,7 @@ sub view {
? $self->snippetPacked
: $self->snippet
;
$output = $self->getToolbar.$output if ($session->var->isAdminOn && !$calledAsWebMethod);
$output = $self->getToolbar.$output if ($session->isAdminOn && !$calledAsWebMethod);
if ($self->processAsTemplate) {
$output = WebGUI::Asset::Template->processRaw($session, $output, $self->get);
}

View file

@ -564,13 +564,13 @@ sub process {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->log->warn('process called on template in trash: '.$self->getId
.'. The template was called through this url: '.$session->asset->url);
return $session->var->isAdminOn ? $i18n->get('template in trash') : '';
return $session->isAdminOn ? $i18n->get('template in trash') : '';
}
elsif ($self->state =~ /^clipboard/) {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->log->warn('process called on template in clipboard: '.$self->getId
.'. The template was called through this url: '.$session->asset->url);
return $session->var->isAdminOn ? $i18n->get('template in clipboard') : '';
return $session->isAdminOn ? $i18n->get('template in clipboard') : '';
}
# Return a JSONinfied version of vars if JSON is the only requested content type.

View file

@ -39,7 +39,7 @@ sub addSessionVars {
$vars->{"session.user.username"} = $self->session->user->username;
$vars->{"session.user.firstDayOfWeek"} = $self->session->user->profileField("firstDayOfWeek");
$vars->{"session.config.extrasurl"} = $self->session->url->extras();
$vars->{"session.var.adminOn"} = $self->session->var->isAdminOn;
$vars->{"session.var.adminOn"} = $self->session->isAdminOn;
$vars->{"session.setting.companyName"} = $self->session->setting->get("companyName");
$vars->{"session.setting.anonymousRegistration"} = $self->session->setting->get("anonymousRegistration");
my $forms = $self->session->form->paramsHashRef();

View file

@ -320,7 +320,7 @@ returns the output.
sub view {
my $self = shift;
my $cache = $self->session->cache;
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
!$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) {
my $out = $cache->get($self->getViewCacheKey);
return $out if $out;
@ -384,7 +384,7 @@ sub view {
}
$p->appendTemplateVars(\%var);
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
if (!$self->session->isAdminOn && $self->cacheTimeout > 10 && !$self->session->form->process("overrideTemplateId") &&
!$self->session->form->process($self->paginateVar) && !$self->session->form->process("makePrintable")) {
$cache->set($self->getViewCacheKey, $out, $self->cacheTimeout);
}

View file

@ -957,7 +957,7 @@ sub view {
##### Process the template
# Add any global variables
# Admin
if ($self->session->var->isAdminOn) {
if ($self->session->isAdminOn) {
$var->{'admin'} = 1;
$var->{'adminControls'} = $self->getToolbar;
}

View file

@ -121,7 +121,7 @@ Dashboard that Visitor would see, or their own.
sub discernUserId {
my $self = shift;
return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId;
return ($self->canManage && $self->session->isAdminOn) ? '1' : $self->session->user->userId;
}
#-------------------------------------------------------------------
@ -243,7 +243,7 @@ turned on.
sub isManaging {
my $self = shift;
return 1 if ($self->canManage && $self->session->var->isAdminOn());
return 1 if ($self->canManage && $self->session->isAdminOn());
return 0;
}
@ -415,7 +415,7 @@ sub view {
}
}
}
$vars{showAdmin} = ($self->session->var->isAdminOn && $self->canEdit);
$vars{showAdmin} = ($self->session->isAdminOn && $self->canEdit);
$vars{"dragger.init"} = '
<script type="text/javascript">
dragable_init("'.$self->getUrl.'");
@ -459,10 +459,10 @@ sub www_view {
unless ($self->canView) {
if ($self->state eq "published") { # no privileges, make em log in
return $self->session->privilege->noAccess();
} elsif ($self->session->var->isAdminOn && $self->state =~ /^trash/) { # show em trash
} elsif ($self->session->isAdminOn && $self->state =~ /^trash/) { # show em trash
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
return undef;
} elsif ($self->session->var->isAdminOn && $self->state =~ /^clipboard/) { # show em clipboard
} elsif ($self->session->isAdminOn && $self->state =~ /^clipboard/) { # show em clipboard
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
return undef;
} else { # tell em it doesn't exist anymore

View file

@ -301,7 +301,7 @@ sub _getFormFields {
$value = $formValue;
}
my $hidden
= ($field->{status} eq 'hidden' && !$session->var->isAdminOn)
= ($field->{status} eq 'hidden' && !$session->isAdminOn)
|| ($field->{isMailField} && !$self->get('mailData'));
# populate Rich Editor field if the field is an HTMLArea
@ -955,7 +955,7 @@ sub getRecordTemplateVars {
for my $field_form (@fields) {
my ($field, $form) = @{ $field_form };
# need a copy
my $hidden = ($field->{status} eq 'hidden' && !$session->var->isAdminOn)
my $hidden = ($field->{status} eq 'hidden' && !$session->isAdminOn)
|| ($field->{isMailField} && !$self->mailData);
# populate Rich Editor field if the field is an HTMLArea

View file

@ -296,7 +296,7 @@ sub view {
my $i18n = WebGUI::International->new($self->session, 'Asset_HttpProxy');
### Set up a cookie jar
my $cookiebox = $self->session->url->escape($self->session->var->get("sessionId"));
my $cookiebox = $self->session->url->escape($self->session->getId);
$cookiebox =~ s/[^A-Za-z0-9\-\.\_]//g; #removes all funky characters
$cookiebox .= '.cookie';
my $jar = HTTP::Cookies->new(File => $self->getCookieJar->getPath($cookiebox), AutoSave => 1, Ignore_Discard => 1);

View file

@ -169,7 +169,7 @@ sub prepareView {
}
my %vars;
$vars{showAdmin} = ($session->var->isAdminOn && $self->canEdit && $self->canEditIfLocked);
$vars{showAdmin} = ($session->isAdminOn && $self->canEdit && $self->canEditIfLocked);
my $splitter = $self->{_viewSplitter} = $self->getSeparator;
@ -369,7 +369,7 @@ override www_view => sub {
my $self = shift;
my $session = $self->session;
# slashdot / burst protection hack
if ($session->var->get("userId") eq "1"
if ($session->user->isVisitor
&& $session->form->param() == 0
&& !$session->scratch->get('isExporting')
) {

View file

@ -479,7 +479,7 @@ sub getListings {
my ($listings, $listingsEncoded);
my $noCache =
$session->var->isAdminOn
$session->isAdminOn
|| $self->listingsCacheTimeout <= 10
|| ($versionTag && $versionTag->getId eq $self->tagId);
my $cache = $session->cache;
@ -645,7 +645,7 @@ sub view {
my $versionTag = WebGUI::VersionTag->getWorking($session, 1);
my $noCache =
$session->var->isAdminOn
$session->isAdminOn
|| $self->statisticsCacheTimeout <= 10
|| ($versionTag && $versionTag->getId eq $self->tagId);
my $cache = $session->cache;

View file

@ -99,7 +99,7 @@ sub view {
my $self = shift;
my $cache = $self->session->cache;
my $cacheKey = $self->getWwwCacheKey( 'view' );
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
my $out = eval { $cache->get( $cacheKey ) };
return $out if $out;
}
@ -112,7 +112,7 @@ sub view {
$var{'submit'} = WebGUI::Form::Submit->new($self->session, {name=>'SearchSubmit',value=>$i18n->get('submit','WebGUI')})->toHtml();
my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
eval { $cache->set( $cacheKey, $out, $self->cacheTimeout) };
}
return $out;

View file

@ -307,7 +307,7 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
override getToolbar => sub {
my $self = shift;
return undef
unless $self->canEdit && $self->session->var->isAdminOn;
unless $self->canEdit && $self->session->isAdminOn;
if ($self->getToolbarState) {
my $toolbar = '';
if ($self->canEditIfLocked) {

View file

@ -435,7 +435,7 @@ sub view {
my $self = shift;
my $cache = $self->session->cache;
my $cacheKey = $self->getWwwCacheKey( 'view' );
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
my $out = eval{ $cache->get( $cacheKey ) };
return $out if $out;
}
@ -461,7 +461,7 @@ sub view {
}
my $out = $self->processTemplate($var,undef,$self->{_viewTemplate});
if (!$self->session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$self->session->isAdminOn && $self->cacheTimeout > 10) {
eval { $cache->set( $cacheKey, $out, $self->cacheTimeout ) };
}
return $out;

View file

@ -368,13 +368,13 @@ sub view {
# try the cached version
my $cache = $session->cache;
my $out = $cache->get("view_".$self->getId);
return $out if ($out ne "" && !$session->var->isAdminOn);
return $out if ($out ne "" && !$session->isAdminOn);
#return $out if $out;
# generate from scratch
my $feed = $self->generateFeed;
$out = $self->processTemplate($self->getTemplateVariables($feed),undef,$self->{_viewTemplate});
if (!$session->var->isAdminOn && $self->cacheTimeout > 10) {
if (!$session->isAdminOn && $self->cacheTimeout > 10) {
$cache->set("view_".$self->getId, $out, $self->cacheTimeout);
}
return $out;

View file

@ -1134,7 +1134,7 @@ sub getViewThingVars {
[$self->getId,$thingId]);
while (my %field = $fields->hash) {
next unless ($field{display} eq '1');
my $hidden = ($field{status} eq "hidden" && !$self->session->var->isAdminOn);
my $hidden = ($field{status} eq "hidden" && !$self->session->isAdminOn);
my $originalValue = $thingData{"field_".$field{fieldId}};
my $value = $self->getFieldValue($originalValue,\%field);
@ -2468,7 +2468,7 @@ sub editThingData {
$field{value} = $fieldValue || $field{defaultValue};
my $formElement .= $self->getFormPlugin(\%field,($resetForm eq ""))->toHtml;
my $hidden = ($field{status} eq "hidden" && !$self->session->var->isAdminOn);
my $hidden = ($field{status} eq "hidden" && !$self->session->isAdminOn);
my $value = $field{value};
$value = $self->getFieldValue($value,\%field);

View file

@ -266,7 +266,7 @@ sub exportAsHtml {
# the exported assets are taken from that user's perspective.
my $exportSession = WebGUI::Session->open($session->config);
my $esGuard = Scope::Guard->new(sub {
$exportSession->var->end;
$exportSession->end;
$exportSession->close;
});
@ -394,7 +394,7 @@ sub exportBranch {
$cs->output->setHandle($handle);
my $guard = guard {
close $handle;
$cs->var->end;
$cs->end;
$cs->close();
$asset->$report('collateral notes', $output) if $output;
};
@ -553,7 +553,7 @@ sub exportGetDescendants {
$session = WebGUI::Session->open($session->config);
$session->user( { userId => $user->userId } );
$sGuard = Scope::Guard->new(sub {
$session->var->end;
$session->end;
$session->close;
});
# clone self in the new session

View file

@ -1229,7 +1229,7 @@ Superclass method that performs standard logout routines.
sub www_logout {
my $self = shift;
$self->session->var->end($self->session->var->get("sessionId"));
$self->session->end();
$self->session->user({userId=>'1'});
my $u = WebGUI::User->new($self->session,1);
$self->{user} = $u;

View file

@ -701,9 +701,9 @@ WebGUI::Asset::Template->newById($self->session,$self->getSetting('accountActiva
$mail->addFooter;
$mail->queue;
$self->user->status("Deactivated");
$session->var->end($session->var->get("sessionId"));
$session->var->start(1,$session->getId);
my $u = WebGUI::User->new($session,1);
$session->end();
$session->start(1, $session->getId);
my $u = WebGUI::User->new($session, 1);
$self->{user} = $u;
$self->logout;
return $self->www_displayLogin($i18n->get('check email for validation','AuthWebGUI'));

View file

@ -83,7 +83,7 @@ sub dispatch {
}
}
$session->clearAsset;
if ($session->var->isAdminOn) {
if ($session->isAdminOn) {
my $asset = WebGUI::Asset->newByUrl($session, $session->url->getRefererUrl) || WebGUI::Asset->getDefault($session);
return $asset->addMissing($assetUrl);
}
@ -163,7 +163,7 @@ The content handler for this package.
sub handler {
my ($session) = @_;
my ($log, $http, $var, $asset, $request, $config) = $session->quick(qw(errorHandler http var asset request config));
my ($log, $http, $asset, $request, $config) = $session->quick(qw(errorHandler http asset request config));
my $output = "";
if (my $perfLog = $log->performanceLogger) { #show performance indicators if required
my $t = [Time::HiRes::gettimeofday()];

View file

@ -34,7 +34,7 @@ process takes one optional parameters for customizing the layout of the Admin ba
sub process {
my $session = shift;
return undef unless $session->var->isAdminOn;
return undef unless $session->isAdminOn;
my $i18n = WebGUI::International->new($session,'Macro_AdminBar');
my ($url, $style, $asset, $user, $config) = $session->quick(qw(url style asset user config));
$style->setScript($url->extras('yui/build/utilities/utilities.js'));

View file

@ -33,7 +33,7 @@ string is returned.
sub process {
my $session = shift;
my @param = @_;
return "" unless ($session->var->isAdminOn);
return "" unless ($session->isAdminOn);
return $param[0];
}

View file

@ -52,7 +52,7 @@ sub process {
my $i18n = WebGUI::International->new($session,'Macro_AdminToggle');
my %var;
$var{'toggle_text'} = $turnOn || $i18n->get(516);
if ($session->var->isAdminOn) {
if ($session->isAdminOn) {
$var{'toggle_url'} = '#'
}
else {

View file

@ -55,7 +55,7 @@ sub process {
if (Exception::Class->caught()) {
$session->log->warn('AssetProxy macro called invalid asset: '.$identifier
.'. The macro was called through this url: '.$session->asset->get('url'));
if ($session->var->isAdminOn) {
if ($session->isAdminOn) {
my $i18n = WebGUI::International->new($session, 'Macro_AssetProxy');
return $i18n->get('invalid url');
}
@ -63,7 +63,7 @@ sub process {
elsif ($asset->get('state') =~ /^trash/) {
$session->log->warn('AssetProxy macro called on asset in trash: '.$identifier
.'. The macro was called through this url: '.$session->asset->get('url'));
if ($session->var->isAdminOn) {
if ($session->isAdminOn) {
my $i18n = WebGUI::International->new($session, 'Macro_AssetProxy');
return $i18n->get('asset in trash');
}
@ -71,7 +71,7 @@ sub process {
elsif ($asset->get('state') =~ /^clipboard/) {
$session->log->warn('AssetProxy macro called on asset in clipboard: '.$identifier
.'. The macro was called through this url: '.$session->asset->get('url'));
if ($session->var->isAdminOn) {
if ($session->isAdminOn) {
my $i18n = WebGUI::International->new($session, 'Macro_AssetProxy');
return $i18n->get('asset in clipboard');
}

View file

@ -55,7 +55,7 @@ sub process {
my $i18n = WebGUI::International->new( $session, 'Macro_EditableToggle' );
my $turnOn = $param[0] || $i18n->get(516);
my $turnOff = $param[1] || $i18n->get(517);
if ( $session->var->isAdminOn ) {
if ( $session->isAdminOn ) {
$var{'toggle.url'} = $session->url->page('op=switchOffAdmin');
$var{'toggle.text'} = $turnOff;
}

View file

@ -96,7 +96,7 @@ sub process {
my $extrasUrl = Path::Class::Dir->new($session->url->make_urlmap_work($session->config->get('extrasURL')));
##Normal mode
if (! $session->var->isAdminOn) {
if (! $session->isAdminOn) {
# Built files live at /path/to/uploads/filepump/bundle.timestamp/ which is
# a sub-dir of uploadsDir, so resolve the dir relative to uploads
my $dir = $bundle->getPathClassDir->relative($uploadsDir);

View file

@ -68,7 +68,7 @@ sub process {
my $templateId = $param[2] || "PBtmpl0000000000000044";
my %var;
my $i18n = WebGUI::International->new($session,'Macro_L_loginBox');
$var{'user.isVisitor'} = ($session->var->get("userId") eq "1");
$var{'user.isVisitor'} = ($session->user->isVisitor);
$var{'customText'} = $param[1];
$var{'customText'} =~ s/%(.*?)%/_createURL($session,$1)/ge;
$var{'hello.label'} = $i18n->get(48);

View file

@ -61,7 +61,7 @@ sub call {
}
require WebGUI::Asset;
my $userId = $session->var->get('userId');
my $userId = $session->get('userId');
return
if grep { $_ eq '1' || $_ eq $userId } @{ $privs->{users} }

View file

@ -53,7 +53,7 @@ $session->form->process("sid"). Afterwards, it calls www_viewActiveSessions.
sub www_killSession {
my $session = shift;
return www_viewActiveSessions($session) if $session->form->process("sid") eq $session->var->get("sessionId");
return www_viewActiveSessions($session) if $session->form->process("sid") eq $session->getId;
return $session->privilege->adminOnly unless canView($session);
$session->db->write("delete from userSession where sessionId=?",[$session->form->process("sid")]);
$session->db->write("delete from userSessionScratch where sessionId=?", [$session->form->process("sid")]);

View file

@ -43,7 +43,7 @@ sub www_adminConsole {
=head2 www_switchOffAdmin ( )
If the current user is in the Turn On Admin Group, then allow them to turn off Admin mode
via WebGUI::Session::Var::switchAdminOff()
via WebGUI::Session::switchAdminOff()
=cut
@ -52,7 +52,7 @@ sub www_switchOffAdmin {
my $session = shift;
return "" unless ($session->user->canUseAdminMode);
$session->http->setCacheControl("none");
$session->var->switchAdminOff();
$session->switchAdminOff();
return "";
}
@ -68,7 +68,7 @@ sub www_switchOnAdmin {
my $session = shift;
return "" unless ($session->user->canUseAdminMode);
$session->http->setCacheControl("none");
$session->var->switchAdminOn();
$session->switchAdminOn();
return "";
}

View file

@ -40,8 +40,8 @@ sub www_ssoViaSessionId {
else {
my ($userId) = $session->db->quickArray("select userId from userSession where sessionId=?",[$sessionId]);
if (defined $userId && $userId ne "") {
$session->var->end;
$session->var->start($userId, $sessionId);
$session->end;
$session->start($userId, $sessionId);
}
}
}

View file

@ -581,7 +581,7 @@ sub www_becomeUser {
my $session = shift;
return $session->privilege->adminOnly() unless canEdit($session) && $session->form->validToken;
return undef unless WebGUI::User->validUserId($session, $session->form->process("uid"));
$session->var->end($session->var->get("sessionId"));
$session->end();
$session->user({userId=>$session->form->process("uid")});
return "";
}

View file

@ -58,8 +58,8 @@ sub add {
my $assetId = shift;
$session->db->write("insert into passiveProfileLog (passiveProfileLogId, userId, sessionId, assetId, dateOfEntry) values (?,?,?,?,?)",
[
$session->id->generate(), $session->user->userId,
$session->var->get("sessionId"), $assetId,
$session->id->generate(), $session->user->userId,
$session->getId, $assetId,
time(),
]);
return undef;

View file

@ -89,7 +89,7 @@ sub addComment {
comment => $comment,
rating => $rating,
date => time(),
ip => $session->var->get('lastIP'),
ip => $session->get('lastIP'),
};
# calculate average

View file

@ -19,7 +19,6 @@ use 5.010;
use CHI;
use File::Temp qw( tempdir );
use Scalar::Util qw( weaken );
use HTTP::Message::PSGI;
use HTTP::Request::Common;
use WebGUI::Config;
@ -39,7 +38,6 @@ use WebGUI::Session::Setting;
use WebGUI::Session::Stow;
use WebGUI::Session::Style;
use WebGUI::Session::Url;
use WebGUI::Session::Var;
=head1 NAME
@ -80,8 +78,7 @@ B<NOTE:> It is important to distinguish the difference between a WebGUI session
$session->style
$session->url
$session->user
$session->var
=head1 METHODS
@ -143,7 +140,7 @@ sub cache {
}
$config->{namespace} ||= $self->config->get('sitename')->[0];
};
$resolveConf->( $cacheConf );
if ( $cacheConf->{l1_cache} ) {
$resolveConf->( $cacheConf->{l1_cache} );
@ -182,12 +179,20 @@ sub close {
# Kill circular references. The literal list is so that the order
# can be explicitly shuffled as necessary.
foreach my $key (qw/_asset _datetime _icon _slave _db _form _http _id _output _privilege _scratch _setting _stow _style _url _user _var _cache _log _response _request/) {
foreach my $key (qw/_asset _datetime _icon _slave _db _form _http _id _output _privilege _scratch _setting _stow _style _url _user _cache _log _response _request/) {
delete $self->{$key};
}
$self->{closed} = 1;
}
#-------------------------------------------------------------------
=head2 closed
Returns true if this session has been closed.
=cut
sub closed {
my $self = shift;
return $self->{closed};
@ -270,7 +275,7 @@ Returns a random slave database handler, if one is defined, otherwise it returns
sub dbSlave {
my $self = shift;
return $self->db if $self->var->isAdminOn;
return $self->db if $self->isAdminOn;
unless (exists $self->{_slave}) {
my @slaves = ();
foreach (1..3) {
@ -325,6 +330,23 @@ sub duplicate {
}
#-------------------------------------------------------------------
=head2 end ( )
Removes the specified session from memory and database.
=cut
sub end {
my $self = shift;
my $id = $self->getId;
$self->cache->remove($id);
$self->scratch->deleteAll;
$self->db->write("delete from userSession where sessionId=?",[$id]);
delete $self->{_user};
}
#-------------------------------------------------------------------
=head2 errorHandler ( )
@ -356,6 +378,51 @@ sub form {
#-------------------------------------------------------------------
=head2 get ( varName )
Retrieves the current value of a session variable.
=head3 varName
The name of the variable.
=head4 lastIP
The last IP address the user came from.
=head4 lastPageView
The epoch date of the last interaction with the session.
=head4 userId
The unique id of the user this session currently bound to.
=head4 adminOn
A boolean indicating whether this session has admin mode enabled or not.
=head4 sessionId
The sessionId associated with this session.
=head4 expires
The epoch date when this user session will expire if it's not accessed again by then.
=cut
sub get {
my $self = shift;
my $varName = shift;
if ($varName) {
return $self->{_var}{$varName};
}
return $self->{_var};
}
#-------------------------------------------------------------------
=head2 getId ( )
Returns the current session Id.
@ -431,6 +498,19 @@ sub id {
}
#-------------------------------------------------------------------
=head2 isAdminOn ( )
Returns a boolean indicating whether admin mode is on or not.
=cut
sub isAdminOn {
my $self = shift;
return $self->get("adminOn");
}
#-------------------------------------------------------------------
=head2 log ( )
@ -468,7 +548,7 @@ If you have a L<PSGI> env hash, you might find the sessionId at: $env->{'psgix.s
=head3 noFuss
Uses simple session vars. See WebGUI::Session::Var::new() for more details.
Uses simple session vars. See WebGUI::Session->open() for more details.
=cut
@ -489,17 +569,49 @@ sub open {
my $request = WebGUI::Session::Request->new($env);
$self->{_request} = $request;
$self->{_response} = $request->new_response( 200 );
# Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it
# wasn't given explicitly
$sessionId ||= $request->cookies->{$config->getCookieName};
# If the sessionId is still unset or is invalid, generate a new one
if (!$sessionId || !$self->id->valid($sessionId)) {
$sessionId = $self->id->generate;
}
$self->{_var} = WebGUI::Session::Var->new($self,$sessionId, $noFuss);
$self->{_var} = $self->cache->get($sessionId);
unless ($self->{_var}{sessionId} eq $sessionId) {
$self->{_var} = $self->db->quickHashRef("select * from userSession where sessionId=?", [$sessionId]);
}
##We have to make sure that the session variable has a sessionId, otherwise downstream users of
##the object will break
if ($noFuss && $self->{_var}{sessionId}) {
$self->{_sessionId} = $self->{_var}{sessionId};
return $self;
}
if ($self->{_var}{expires} && $self->{_var}{expires} < time()) { ##Session expired, start a new one with the same Id, as visitor
$self->end;
$self->start(1, $sessionId);
}
elsif ($self->{_var}{sessionId} ne "") { ##Fetched an existing session. Update variables with recent data.
my $time = time();
my $timeout = $self->setting->get("sessionTimeout");
$self->{_sessionId} = $self->{_var}{sessionId};
$self->{_var}{lastPageView} = $time;
$self->{_var}{lastIP} = $self->request->address;
$self->{_var}{expires} = $time + $timeout;
if ($self->{_var}{nextCacheFlush} > 0 && $self->{_var}{nextCacheFlush} < $time) {
delete $self->{_var}{nextCacheFlush};
$self->db->setRow("userSession","sessionId",$self->{_var});
}
else {
$self->{_var}{nextCacheFlush} = $time + $self->config->get("hotSessionFlushToDb");
$self->cache->set($sessionId, $self->{_var}, $timeout);
}
}
else { ##Start a new default session with the requested, non-existant id.
$self->start(1,$sessionId);
}
return $self;
}
@ -630,6 +742,45 @@ sub setting {
}
#-------------------------------------------------------------------
=head2 start ( [ userId, sessionId ] )
Start a new user session. Returns the user session id. The session variable's sessionId
is set to the var object's session id. Also sets the user's CSRF token.
=head3 userId
The user id of the user to create a session for. Defaults to 1 (Visitor).
=head3 sessionId
Session id will be generated if not specified. In almost every case you should let the system generate the session id.
=cut
sub start {
my $self = shift;
my $userId = shift;
$userId = 1 if ($userId eq "");
my $sessionId = shift;
$sessionId = $self->id->generate if ($sessionId eq "");
my $timeout = $self->setting->get('sessionTimeout');
my $time = time();
$self->{_var} = {
expires => $time + $timeout,
lastPageView => $time,
lastIP => $self->request->address,
adminOn => 0,
userId => $userId
};
$self->{_sessionId} = $sessionId;
$self->cache->set($sessionId, $self->{_var}, $timeout);
delete $self->{_var}{nextCacheFlush};
$self->db->setRow("userSession","sessionId",$self->{_var}, $sessionId);
$self->scratch->set('webguiCsrfToken', $self->id->generate); # create cross site request forgery token
}
#-------------------------------------------------------------------
=head2 stow ( )
@ -663,6 +814,38 @@ sub style {
}
#-------------------------------------------------------------------
=head2 switchAdminOff ( )
Disables admin mode.
=cut
sub switchAdminOff {
my $self = shift;
$self->{_var}{adminOn} = 0;
$self->cache->set($self->getId, $self->{_var}, $self->setting->get('sessionTimeout'));
delete $self->{_var}{nextCacheFlush};
$self->db->setRow("userSession","sessionId", $self->{_var});
}
#-------------------------------------------------------------------
=head2 switchAdminOn ( )
Enables admin mode.
=cut
sub switchAdminOn {
my $self = shift;
$self->{_var}{adminOn} = 1;
$self->cache->set($self->getId, $self->{_var}, $self->setting->get('sessionTimeout'));
delete $self->{_var}{nextCacheFlush};
$self->db->setRow("userSession","sessionId", $self->{_var});
}
#-------------------------------------------------------------------
=head2 url ( )
@ -704,15 +887,16 @@ sub user {
my $option = shift;
if (defined $option) {
my $userId = $option->{userId} || $option->{user}->userId;
$self->var->start($userId,$self->getId);
$self->start($userId,$self->getId);
if ($self->setting->get("passiveProfilingEnabled")) {
$self->db->write("update passiveProfileLog set userId = ? where sessionId = ?",[$userId,$self->getId]);
}
delete $self->{_stow};
$self->{_user} = $option->{user} || WebGUI::User->new($self, $userId);
$self->request->env->{REMOTE_USER} = $self->{_user}->username if $self->request;
} elsif (!exists $self->{_user}) {
$self->{_user} = WebGUI::User->new($self, $self->var->get('userId'));
}
elsif (!exists $self->{_user}) {
$self->{_user} = WebGUI::User->new($self, $self->get('userId'));
$self->request->env->{REMOTE_USER} = $self->{_user}->username if $self->request;
}
return $self->{_user};
@ -723,16 +907,14 @@ sub user {
=head2 var ( )
DEPRECATED. Session::Var was absorbed into Session in WebGUI 8.0.
Returns a reference to the WebGUI::Session::Var object.
=cut
sub var {
my $self = shift;
unless ($self->{_var}) {
$self->{_var} = WebGUI::Session::Var->new($self);
}
return $self->{_var};
return $_->[0];
}
1;

View file

@ -251,13 +251,14 @@ sub sendHeader {
return undef if ($self->{_http}{noHeader});
return $self->_sendMinimalHeader unless defined $self->session->db(1);
my ($request, $response, $config, $var) = $self->session->quick(qw(request response config var));
my $session = $self->session;
my ($request, $response, $config) = $session->quick(qw(request response config ));
return undef unless $request;
my $userId = $var->get("userId");
my $userId = $session->get("userId");
# send webgui session cookie
my $cookieName = $config->getCookieName;
$self->setCookie($cookieName,$var->getId, $config->getCookieTTL, $config->get("cookieDomain")) unless $var->getId eq $request->cookies->{$cookieName};
$self->setCookie($cookieName, $session->getId, $config->getCookieTTL, $config->get("cookieDomain")) unless $session->getId eq $request->cookies->{$cookieName};
$self->setNoHeader(1);
my %params;

View file

@ -1,297 +0,0 @@
package WebGUI::Session::Var;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Scalar::Util qw(weaken);
=head1 NAME
Package WebGUI::Session::Var
=head1 DESCRIPTION
This package is the persistence layer for WebGUI session variables.
=head1 SYNOPSIS
$var = WebGUI::Session::Var->new($session);
$value = $var->get('lastIP');
$var->start;
$var->end;
$boolean = $var->isAdminOn;
$var->switchAdminOff;
$var->switchAdminOn;
=head1 METHODS
These methods are available from this package:
=cut
#-------------------------------------------------------------------
=head2 end ( )
Removes the specified user session from memory and database.
=cut
sub end {
my $self = shift;
my $session = $self->session;
my $id = $self->getId;
$session->cache->remove($id);
$session->scratch->deleteAll;
$session->db->write("delete from userSession where sessionId=?",[$id]);
delete $session->{_user};
}
#-------------------------------------------------------------------
=head2 get ( varName )
Retrieves the current value of a session variable.
=head3 varName
The name of the variable.
=head4 lastIP
The last IP address the user came from.
=head4 lastPageView
The epoch date of the last interaction with the session.
=head4 userId
The unique id of the user this session currently bound to.
=head4 adminOn
A boolean indicating whether this session has admin mode enabled or not.
=head4 sessionId
The sessionId associated with this session.
=head4 expires
The epoch date when this user session will expire if it's not accessed again by then.
=cut
sub get {
my $self = shift;
my $var = shift;
return $self->{_var}{$var};
}
#-------------------------------------------------------------------
=head2 getId ( )
Returns the ID of the current session.
=cut
sub getId {
my $self = shift;
$self->get("sessionId");
}
#-------------------------------------------------------------------
=head2 isAdminOn ( )
Returns a boolean indicating whether admin mode is on or not.
=cut
sub isAdminOn {
my $self = shift;
return $self->get("adminOn");
}
#-------------------------------------------------------------------
=head2 new ( session, sessionId, noFuss )
Constructor. Overwrites the sessionId of $session with its own id. Returns a var object.
=head3 session
A reference to the session.
=head3 sessionId
The specific sessionId you want to instantiate.
=head3 noFuss
A boolean, that if true will not update the session, or check if it's
expired. This is mainly for WebGUI session maintenance, and shouldn't
normally be used by anyone.
=cut
sub new {
my ($class, $session, $sessionId, $noFuss) = @_;
my $self = bless { _session => $session }, $class;
weaken $self->{_session};
if ($sessionId eq "") { ##New session
$self->start(1);
}
else { ##existing session requested
$self->{_var} = $session->cache->get($sessionId);
unless ($self->{_var}{sessionId} eq $sessionId) {
$self->{_var} = $session->db->quickHashRef("select * from userSession where sessionId=?",[$sessionId]);
}
##We have to make sure that the session variable has a sessionId, otherwise downstream users of
##the object will break
if ($noFuss && $self->{_var}{sessionId}) {
$self->session->{_sessionId} = $self->{_var}{sessionId};
return $self;
}
if ($self->{_var}{expires} && $self->{_var}{expires} < time()) { ##Session expired, start a new one with the same Id
$self->end;
$self->start(1,$sessionId);
}
elsif ($self->{_var}{sessionId} ne "") { ##Fetched an existing session. Update variables with recent data.
my $time = time();
my $timeout = $session->setting->get("sessionTimeout");
$self->{_var}{lastPageView} = $time;
$self->{_var}{lastIP} = $session->request->address;
$self->{_var}{expires} = $time + $timeout;
if ($self->{_var}{nextCacheFlush} > 0 && $self->{_var}{nextCacheFlush} < $time) {
delete $self->{_var}{nextCacheFlush};
$session->db->setRow("userSession","sessionId",$self->{_var});
}
else {
$self->{_var}{nextCacheFlush} = $time + $session->config->get("hotSessionFlushToDb");
$session->cache->set($sessionId, $self->{_var}, $timeout);
}
$self->session->{_sessionId} = $self->{_var}{sessionId};
return $self;
}
else { ##Start a new default session with the requested, non-existant id.
$self->start(1,$sessionId);
}
}
return $self;
}
#-------------------------------------------------------------------
=head2 session ( )
Returns a reference to the session object.
=cut
sub session {
my $self = shift;
return $self->{_session};
}
#-------------------------------------------------------------------
=head2 start ( [ userId, sessionId ] )
Start a new user session. Returns the user session id. The session variable's sessionId
is set to the var object's session id. Also sets the user's CSRF token.
=head3 userId
The user id of the user to create a session for. Defaults to 1 (Visitor).
=head3 sessionId
Session id will be generated if not specified. In almost every case you should let the system generate the session id.
=cut
sub start {
my $self = shift;
my $userId = shift;
$userId = 1 if ($userId eq "");
my $sessionId = shift;
my $session = $self->session;
my $id = $session->id;
$sessionId = $id->generate if ($sessionId eq "");
my $timeout = $session->setting->get('sessionTimeout');
my $time = time();
$self->{_var} = {
expires => $time + $timeout,
lastPageView => $time,
lastIP => $session->request->address,
adminOn => 0,
userId => $userId
};
$self->session->{_sessionId} = $sessionId;
$session->cache->set($sessionId, $self->{_var}, $timeout);
delete $self->{_var}{nextCacheFlush};
$session->db->setRow("userSession","sessionId",$self->{_var},$sessionId);
$self->{_sessionId} = $sessionId;
$session->scratch->set('webguiCsrfToken', $id->generate); # create cross site request forgery token
}
#-------------------------------------------------------------------
=head2 switchAdminOff ( )
Disables admin mode.
=cut
sub switchAdminOff {
my $self = shift;
$self->{_var}{adminOn} = 0;
my $session = $self->session;
$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'));
delete $self->{_var}{nextCacheFlush};
$session->db->setRow("userSession","sessionId", $self->{_var});
}
#-------------------------------------------------------------------
=head2 switchAdminOn ( )
Enables admin mode.
=cut
sub switchAdminOn {
my $self = shift;
$self->{_var}{adminOn} = 1;
my $session = $self->session;
$session->cache->set($self->getId, $self->{_var}, $session->setting->get('sessionTimeout'));
delete $self->{_var}{nextCacheFlush};
$self->session->db->setRow("userSession","sessionId", $self->{_var});
}
1;

View file

@ -716,7 +716,7 @@ Example call:
},
'WebGUI::Session' => sub {
my $session = shift;
$session->var->end;
$session->end;
$session->close;
},
'WebGUI::LDAPLink' => sub {
@ -832,7 +832,7 @@ sub cleanup {
while @guarded;
if ( our $SESSION ) {
$SESSION->var->end;
$SESSION->end;
$SESSION->close;
undef $SESSION;
}

View file

@ -88,7 +88,7 @@ sub DESTROY {
my $self = shift;
try {
my $session = $self->session;
$session->var->end;
$session->end;
$session->close;
};
}

View file

@ -46,7 +46,7 @@ sub run {
}
$versionTag->commit;
$session->var->end;
$session->end;
$session->close;
return $package;

View file

@ -113,7 +113,7 @@ sub _build_exports {
if (WebGUI::VersionTag->getWorking($session, 'nocreate')) {
$version_tag_sub->()->commit;
}
$session->var->end;
$session->end;
$session->close;
}
undef $session;

View file

@ -263,7 +263,7 @@ sub commitAsUser {
}
}
#End the new session
$new_session->var->end;
$new_session->end;
$new_session->close;
return 1;
}

View file

@ -89,7 +89,7 @@ sub execute {
}
my $session = WebGUI::Session->open($self->session->config, undef, $sessionId, 1);
if (defined $session) {
$session->var->end;
$session->end;
$session->close;
}
if ((time() - $time) > $ttl) {

View file

@ -506,10 +506,10 @@ TODO: {
################################################################
$session->user({ userId => 3 });
$session->var->switchAdminOff;
$session->switchAdminOff;
is($rootAsset->addMissing('/nowhereMan'), undef, q{addMissing doesn't return anything unless user is in Admin Mode});
$session->var->switchAdminOn;
$session->switchAdminOn;
my $addMissing = $rootAsset->addMissing('/nowhereMan');
ok($addMissing, 'addMissing returns some output when in Admin Mode');
@ -858,7 +858,7 @@ $clippedAsset->cut;
is $trashedAsset->get('state'), 'trash', 'checkView setup: trashed an asset';
is $clippedAsset->get('state'), 'clipboard', '... clipped an asset';
$session->var->switchAdminOff;
$session->switchAdminOff;
$session->http->setRedirectLocation('');
$session->http->setStatus(200, 'OK');
@ -871,7 +871,7 @@ $clippedAsset->checkView();
is $session->http->getStatus, 410, '... status set to 410 for cut asset';
is $session->http->getRedirectLocation, '', '... no redirect set';
$session->var->switchAdminOn;
$session->switchAdminOn;
$session->http->setStatus(200, 'OK');
is $trashedAsset->checkView(), 'chunked', '... returns "chunked" when admin is on for trashed asset';
is $session->http->getRedirectLocation, $trashedAsset->getUrl('func=manageTrash'), '... trashed asset sets redirect to manageTrash';

View file

@ -161,7 +161,7 @@ $template3rev->purgeRevision();
## Check how templates in the trash and clipboard are handled.
$session->asset($importNode);
$session->var->switchAdminOff;
$session->switchAdminOff;
my $trashTemplate = $importNode->addChild({
className => "WebGUI::Asset::Template",
@ -175,7 +175,7 @@ is($trashTemplate->process, '', 'process: returns nothing when the template is i
$trashTemplate->cut;
is($trashTemplate->process, '', '... returns nothing when the template is in the trash, and admin mode is off');
$session->var->switchAdminOn;
$session->switchAdminOn;
$trashTemplate->trash;
is($trashTemplate->process, 'Template in trash', '... returns message when the template is in the trash, and admin mode is on');
@ -183,7 +183,7 @@ is($trashTemplate->process, 'Template in trash', '... returns message when the t
$trashTemplate->cut;
is($trashTemplate->process, 'Template in clipboard', '... returns message when the template is in the trash, and admin mode is on');
$session->var->switchAdminOff;
$session->switchAdminOff;
# Check error logging for bad templates

View file

@ -124,12 +124,12 @@ isnt( $output, "www_view", "?func= dispatch cancelled because of unhandled fragm
$td->cut();
$output = $td->dispatch();
is $output, undef, 'dispatch returns undef when trying to access an asset that is not published, and admin is not on';
$session->var->switchAdminOn;
$session->switchAdminOn;
$output = $td->dispatch();
is $output, 'www_view', 'when admin is on, the asset can be accessed';
$td->publish();
$session->var->switchAdminOff;
$session->switchAdminOff;
$output = $td->dispatch();
is $output, 'www_view', 'asset state restored for next tests';

View file

@ -24,7 +24,7 @@ plan tests => 2;
my $output;
$output = WebGUI::Macro::AdminBar::process($session);
is($output, undef, 'AdminBar returns undef unless admin is on');
$session->var->switchAdminOn;
$session->switchAdminOn;
$output = WebGUI::Macro::AdminBar::process($session);
ok($output, 'AdminBar returns something when admin is on');

View file

@ -31,7 +31,7 @@ $session->user({userId => 3});
$output = WebGUI::Macro::AdminText::process($session, 'admin');
is($output, '', 'user is admin, not in admin mode');
$session->var->switchAdminOn;
$session->switchAdminOn;
$output = WebGUI::Macro::AdminText::process($session, 'admin');
is($output, 'admin', 'admin in admin mode');
@ -41,6 +41,6 @@ is($output, '', 'null text');
$output = WebGUI::Macro::AdminText::process($session);
is($output, undef, 'undef text');
$session->var->switchAdminOff;
$session->switchAdminOff;
$output = WebGUI::Macro::AdminText::process($session, 'admin');
is($output, '', 'user is admin, not in admin mode');

View file

@ -197,12 +197,12 @@ foreach my $testSet (@testSets) {
$session->user({userId=>$testSet->{userId}});
$session->asset($testSet->{asset});
if ($testSet->{adminStatus} eq 'off') {
$session->var->switchAdminOff();
$session->switchAdminOff();
$testSet->{label} = $testSet->{onText} || $i18n->get(516);
$testSet->{url} = $session->url->page('op=switchOnAdmin'),
}
elsif ($testSet->{adminStatus} eq 'on') {
$session->var->switchAdminOn();
$session->switchAdminOn();
$testSet->{label} = $testSet->{offText} || $i18n->get(517);
$testSet->{url} = $session->url->page('op=switchOffAdmin'),
}

View file

@ -92,7 +92,7 @@ is(
'... check illegal file type access returns empty string'
);
$session->var->switchAdminOn();
$session->switchAdminOn();
is(
WebGUI::Macro::FilePump::process($session, 'test bundle', 'JS'),
sprintf(qq|<script type="text/javascript" src="%s" ></script>\n<script type="text/javascript" src="%s" ></script>\n|,

View file

@ -15,7 +15,6 @@ use JSON;
use WebGUI::Test;
use WebGUI::International;
use WebGUI::Session;
use WebGUI::Session::Var;
use WebGUI::User;
use WebGUI::Macro::UsersOnline;

View file

@ -16,8 +16,7 @@ use WebGUI::Session;
use WebGUI::User;
use Test::More;
plan tests => 5; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
@ -32,12 +31,14 @@ is($userId, $user->userId, 'changing session user changes sessionId inside userS
$session->user({userId => 3});
is($session->user->userId, 3, 'Set session user to Admin, check userId==3');
is($session->user->profileField('uiLevel'), 9, 'Set session user to Admin, check uiLevel==9');
is($session->user->get('uiLevel'), 9, 'Set session user to Admin, check uiLevel==9');
my $dupe = $session->duplicate;
WebGUI::Test->addToCleanup($dupe);
is $session->getId, $dupe->getId, 'duplicated session has the same sessionId';
is($session->get('sessionId'), $session->getId, 'getId returns sessionId');
is $dupe->getId, $session->getId, 'duplicated session has the same sessionId';
################################################################
#
@ -59,4 +60,159 @@ WebGUI::Test->addToCleanup(sub {$session->config->delete('dbslave2');});
my $slave2 = $session->dbSlave;
isa_ok($slave2, 'WebGUI::SQL::db');
cmp_ok($session->get("lastPageView"), '>', 0, "lastPageView set to something");
can_ok($session, qw/isAdminOn switchAdminOn switchAdminOff/);
is($session->isAdminOn, 0, "isAdminOn()");
$session->switchAdminOn;
is($session->isAdminOn, 1, "switchAdminOn()");
$session->switchAdminOff;
is($session->isAdminOn, 0, "switchAdminOff()");
my $token = $session->scratch->get('webguiCsrfToken');
ok( $token, 'CSRF token set');
ok( $session->id->valid($token), '...is a valid GUID');
my $id = $session->getId;
my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?", [$id]);
is($count, 1, "created an user session entry in the database");
my $env;
$session->request->env->{REMOTE_ADDR} = '192.168.0.34';
my $varSession = WebGUI::Session->open($session->config, $session->request->env);
WebGUI::Test->addToCleanup($varSession);
my $varTime = time();
isnt($varSession->scratch->get('webguiCsrfToken'), $token, '... calling new without sessionId creates a new token');
isnt($varSession->getId, $session->getId, "new session has a different id from current session");
my $varExpires = $varTime + $session->setting->get('sessionTimeout');
cmp_ok(abs($varSession->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly');
cmp_ok(abs($varSession->get('expires') - $varExpires), '<=', 1, 'expires set correctly');
is($varSession->get('userId'), 1, 'default userId is 1');
is($varSession->get('adminOn'), $varSession->isAdminOn, "get('adminOn') and isAdminOn return the same thing");
is($varSession->get('adminOn'), 0, "adminOn is off by default"); ##retest
is($varSession->get('lastIP'), '192.168.0.34', "lastIP fetched");
my $illegalSessionId = 'illegalSessionIdThatIsTooLong';
# '1234567890123456789012'
my $varIllegal = WebGUI::Session->open($session->config, undef, );
WebGUI::Test->addToCleanup($varIllegal);
isa_ok($varIllegal, 'WebGUI::Session', 'invalid sessionId will still produce a Session object');
ok($session->id->valid($varIllegal->getId), 'valid ID created for the new session, when bad Id was suggested');
ok(index($varIllegal->getId, $illegalSessionId) == -1, 'illegal session was not truncated to make the new Id');
$session->request->env->{REMOTE_ADDR} = '10.0.0.5';
my $varCopy = WebGUI::Session->open($session->config, $session->request->env, $varSession->getId);
is($varCopy->scratch->get('webguiCsrfToken'), $varSession->scratch->get('webguiCsrfToken'), 'opening a copy of a user session did not change the CSRF token');
cmp_deeply(
$varCopy,
methods(
['get', 'sessionId'] => $varSession->get('sessionId'),
['get', 'userId'] => $varSession->get('userId'),
['get', 'adminOn'] => $varSession->get('adminOn'),
),
'similar methods in copy of original var object'
);
is($varCopy->get('lastIP'), '10.0.0.5', "lastIP set on copy");
my $varSessionId = $varSession->getId;
$varSession->end;
($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$varSession->getId]);
ok($count == 0,"end() removes current entry from database");
{
my $sessionId = 'nonExistantIdButValid0';
# '1234567890123456789012'
my $testSession = WebGUI::Session->open($session->config, undef, $sessionId);
my $guard = WebGUI::Test->cleanupGuard($testSession);
isa_ok($testSession, 'WebGUI::Session', 'non-existant sessionId will still produce a Var object');
is($testSession->getId, $sessionId, 'user session Id set to non-existant Id');
}
{
my $expire = WebGUI::Session->open($session->config);
my $guard = WebGUI::Test->cleanupGuard($expire);
$expire->switchAdminOn;
# jury rig the database and the cache to expire
my $expire_time = $expire->get('lastPageView') - 1;
$session->db->write("update userSession set userId=?, expires=? where sessionId=?", [3, $expire_time, $expire->getId]);
$session->user({userId => 3});
my $copyOfSession = { %{ $expire->get() } };
$copyOfSession->{expires} = $expire_time;
$session->cache->set($expire->getId, $copyOfSession);
my $copy = WebGUI::Session->open($session->config, undef, $expire->getId);
my $guard2 = WebGUI::Test->cleanupGuard($copy);
is $copy->getId, $expire->getId, 'new Var object has correct id';
isnt $copy->isAdminOn, $expire->isAdminOn, 'new adminOn not equal to old adminOn';
is $copy->isAdminOn, 0, 'new Var object has default adminOn';
isnt $copy->get('userId'), 3, 'new userId not equal to old userId';
}
{
##Var objects for noFuss tests
my $trial = WebGUI::Session->open($session->config);
my $expiring = WebGUI::Session->open($session->config);
my $guard = WebGUI::Test->cleanupGuard($trial, $expiring);
$session->db->write("update userSession set expires=? where sessionId=?", [$expiring->get('lastPageView')-5, $expiring->getId]);
$expiring->{_var}{expires} = $expiring->get('lastPageView')-5;
##Valid fetch with no fuss
my $varTest = WebGUI::Session->open($session->config, $session->request->env, $trial->getId, 1);
my $guard2 = WebGUI::Test->cleanupGuard($varTest);
cmp_deeply(
$varTest,
methods(
['get', 'sessionId'] => $trial->getId,
['get', 'userId'] => 1,
['get', 'adminOn'] => 0,
['get', 'lastIP'] => '127.0.0.1',
['get', 'expires'] => $trial->get('expires'),
['get', 'lastPageView'] => $trial->get('lastPageView'),
),
'fetching a valid session with noFuss does not update the object info'
);
##Test a valid fetch
my $expired = WebGUI::Session->open($session->config, undef, $expiring->getId, 1);
my $guard3 = WebGUI::Test->cleanupGuard($expired);
cmp_deeply(
$expired,
methods(
['get', 'sessionId'] => $expiring->getId,
['get', 'userId'] => 1,
['get', 'adminOn'] => 0,
['get', 'lastIP'] => '127.0.0.1',
['get', 'lastPageView'] => $expiring->get('lastPageView'),
['get', 'expires'] => $expiring->get('expires'),
),
'fetching a valid session with noFuss does not update the object info, even if it has expired'
);
}
my $varId4 = 'idDoesNotExist00779988';
# '1234567890123456789012'
my $varTest = WebGUI::Session->open($session->config, undef, $varId4, 1);
WebGUI::Test->addToCleanup($varTest);
isa_ok($varTest, "WebGUI::Session", "non-existant Id with noFuss returns a valid object...");
is($varTest->getId, $varId4, "...and we got our requested Id");
$varTest->start(3, $varTest->getId);
is($varTest->get('userId'), 3, 'userId set via start');
$varTest->start("", $varTest->getId);
is($varTest->get('userId'), 1, 'calling start with null userId returns default user (visitor)');
done_testing;
#vim:ft=perl

View file

@ -32,7 +32,7 @@ use Test::MockObject::Extends;
##try and implement the mod_perl cookie handling code.
$http = Test::MockObject::Extends->new($http);
my $cookieName = $session->config->getCookieName;
my $varId = $session->var->getId();
my $varId = $session->getId();
$http->mock( getCookies => sub { return {$cookieName => $varId} } );

View file

@ -1,216 +0,0 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Session::Var;
use Test::More tests => 44; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
ok($session->var->getId ne "", "getId()");
cmp_ok($session->var->get("lastPageView"), '>', 0, "get(lastPageView)");
is($session->var->isAdminOn, 0, "isAdminOn()");
$session->var->switchAdminOn;
is($session->var->isAdminOn, 1, "switchAdminOn()");
$session->var->switchAdminOff;
is($session->var->isAdminOn, 0, "switchAdminOff()");
my $token = $session->scratch->get('webguiCsrfToken');
ok( $token, 'CSRF token set');
ok( $session->id->valid($token), '...is a valid GUID');
my $id = $session->var->getId;
my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$id]);
is($count, 1, "created an user session entry in the database");
my $env = $session->request->env;
$env->{REMOTE_ADDR} = '192.168.0.34';
my $var = WebGUI::Session::Var->new($session);
my $varTime = time();
my $varExpires = $varTime + $session->setting->get('sessionTimeout');
isa_ok($var, 'WebGUI::Session::Var', 'new returns Var object');
isnt($session->scratch->get('webguiCsrfToken'), $token, '... calling new without sessionId creates a new token');
$token = $session->scratch->get('webguiCsrfToken');
cmp_ok(abs($var->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly');
cmp_ok(abs($var->get('expires') - $varExpires), '<=', 1, 'expires set correctly');
is($var->get('userId'), 1, 'default userId is 1');
is($var->get('sessionId'), $var->getId, "get('sessionId') and getId return the same thing");
isnt($var->getId, $session->var->getId, "a sessionId different from our Session's var sessionId was created");
is($var->getId, $session->getId, 'SessionId set to userSessionId from var');
is($var->get('adminOn'), $var->isAdminOn, "get('adminOn') and isAdminOn return the same thing");
is($var->get('adminOn'), 0, "adminOn is off by default"); ##retest
is($var->get('lastIP'), '192.168.0.34', "lastIP fetched");
isa_ok($var->session, 'WebGUI::Session', 'session method returns a Session object');
is($var->session->getId, $session->getId, 'session method returns our Session object');
sleep(2);
$env->{REMOTE_ADDR} = '10.0.5.5';
#Grab a more recent version of our user session object
$varTime = time();
my $var2 = WebGUI::Session::Var->new($session, $session->getId);
$varExpires = $varTime + $session->setting->get('sessionTimeout');
is($var2->session->scratch->get('webguiCsrfToken'), $token, 'opening a new user session did not change the CSRF token');
cmp_deeply(
$var2,
methods(
['get', 'sessionId'] => $var->get('sessionId'),
['get', 'userId'] => $var->get('userId'),
['get', 'adminOn'] => $var->get('adminOn'),
),
'similar methods in copy of original var object'
);
cmp_ok(abs($var2->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly on copy');
cmp_ok(abs($var2->get('expires') - $varExpires), '<=', 1, 'expires set correctly on copy');
is($var2->get('lastIP'), '10.0.5.5', "lastIP set on copy");
my $var2Id = $var2->getId;
$var2->end;
($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$var2->getId]);
ok($count == 0,"end() removes current entry from database");
$var->end;
$var2 = WebGUI::Session::Var->new($session, 'illegalSessionIdThatIsTooLong');
# '1234567890123456789012'
isa_ok($var2, 'WebGUI::Session::Var', 'invalid sessionId will still produce a Var object');
($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$var2->getId]);
is($count, 0, "object store of sessionId does not match database record");
$var2Id = $var2->getId;
$var2->end;
my $idToDelete = substr $var2Id,0,22;
($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$idToDelete]);
is($count, 1, "Unable to delete database record for Var object with invalid sessionId");
my $varId3 = 'nonExistantIdButValid0';
# '1234567890123456789012'
$var = WebGUI::Session::Var->new($session, $varId3);
isa_ok($var, 'WebGUI::Session::Var', 'non-existant sessionId will still produce a Var object');
is($var->getId, $varId3, 'user session Id set to non-existant Id');
is($session->getId, $varId3, 'session Id set to non-existant Id');
cmp_deeply(
$var,
methods(
['get', 'sessionId'] => $varId3,
['get', 'userId'] => 1,
['get', 'adminOn'] => 0,
['get', 'lastIP'] => '10.0.5.5',
),
'non-existant Id returns default values'
);
$var->end;
##Grab a new Var object that we'll expire. We'll detect the expiration
##by looking for admin status and userId
$var2 = WebGUI::Session::Var->new($session);
$var2->switchAdminOn;
# jury rig the database and the cache to expire
$session->db->write("update userSession set userId=? where sessionId=?",
[3, $var2->getId]);
$session->db->write("update userSession set expires=? where sessionId=?",
[$var2->get('lastPageView')-1, $var2->getId]);
my %copyOfVar2 = %{$var2->{_var}};
$copyOfVar2{expires} = $var2->get('lastPageView')-1;
$copyOfVar2{userId} = 3;
$session->cache->set($var2->getId, \%copyOfVar2);
my $var3 = WebGUI::Session::Var->new($session, $var2->getId);
is $var3->getId, $var2->getId, 'new Var object has correct id';
isnt $var3->isAdminOn, $var2->isAdminOn, 'new adminOn not equal to old adminOn';
is $var3->isAdminOn, 0, 'new Var object has default adminOn';
isnt $var3->get('userId'), 3, 'new userId not equal to old userId';
$var2->end;
$var3->end;
##Var objects for noFuss tests
my $var4 = WebGUI::Session::Var->new($session);
my $varExpiring = WebGUI::Session::Var->new($session);
$session->db->write("update userSession set expires=? where sessionId=?",
[$varExpiring->get('lastPageView')-1, $varExpiring->getId]);
$varExpiring->{_var}{expires} = $varExpiring->get('lastPageView')-1;
sleep 1;
$env->{REMOTE_ADDR} = '127.0.0.1';
##Test a valid fetch
my $varTest = WebGUI::Session::Var->new($session, $var4->getId, 1);
cmp_deeply(
$varTest,
methods(
['get', 'sessionId'] => $var4->getId,
['get', 'userId'] => 1,
['get', 'adminOn'] => 0,
['get', 'lastIP'] => '10.0.5.5',
['get', 'expires'] => $var4->get('expires'),
['get', 'lastPageView'] => $var4->get('lastPageView'),
),
'fetching a valid session with noFuss does not update the object info'
);
$varTest->end;
$var4->end;
##Test a valid fetch
$varTest = WebGUI::Session::Var->new($session, $varExpiring->getId, 1);
cmp_deeply(
$varTest,
methods(
['get', 'sessionId'] => $varExpiring->getId,
['get', 'userId'] => 1,
['get', 'adminOn'] => 0,
['get', 'lastIP'] => '10.0.5.5',
['get', 'lastPageView'] => $varExpiring->get('lastPageView'),
['get', 'expires'] => $varExpiring->get('expires'),
),
'fetching a valid session with noFuss does not update the object info, even if it has expired'
);
$varExpiring->end;
$varTest->end;
my $varId4 = 'idDoesNotExist00779988';
# '1234567890123456789012'
$varTest = WebGUI::Session::Var->new($session, $varId4, 1);
isa_ok($varTest, "WebGUI::Session::Var", "non-existant Id with noFuss returns a valid object...");
is($varTest->getId, $varId4, "...and we got our requested Id");
$varTest->start(3, $varTest->getId);
is($varTest->get('userId'), 3, 'userId set via start');
$varTest->start("", $varTest->getId);
is($varTest->get('userId'), 1, 'calling start with null userId returns default user (visitor)');
END {
foreach my $varObj ($var, $var2, $var3, $var4, $varExpiring, $varTest) {
if (defined $varObj and ref $varObj eq 'WebGUI::Session::Var') {
$varObj->end();
}
}
$session->db->write("delete from userSession where sessionId=?",[$idToDelete]);
}

View file

@ -93,7 +93,7 @@ is ($newSessionCount, $sessionCount+2, 'two of the sessions were deleted');
is ($newScratchCount, $scratchCount+2, 'scratch from both sessions cleaned up');
foreach my $testSession (@sessions) {
$testSession->var->end;
$testSession->end;
$testSession->close;
}