comment out the ip filter from clientCheck (in Session::Env)
added form validation to AdSku ( with internationalized messages )
This commit is contained in:
parent
a6a70a46e0
commit
9d0f7869b3
3 changed files with 97 additions and 16 deletions
|
|
@ -19,8 +19,10 @@ use Tie::IxHash;
|
|||
use base 'WebGUI::Asset::Sku';
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::Shop::Pay;
|
||||
use WebGUI::AssetCollateral::Sku::Ad::Ad;
|
||||
use WebGUI::AdSpace;
|
||||
use WebGUI::AdSpace::Ad;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -359,7 +361,7 @@ sub onRemoveFromCart {
|
|||
my $self = shift;
|
||||
my $item = shift;
|
||||
my $options = $self->getOptions;
|
||||
WebGUI::Storage->new($self->session,$options->{'image'})->delete;
|
||||
WebGUI::Storage->get($self->session,$options->{'image'})->delete;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -463,6 +465,7 @@ sub view {
|
|||
. WebGUI::Form::hidden( $session, { name=>"func", value=>"addToCart" }),
|
||||
formFooter => WebGUI::Form::formFooter($session),
|
||||
formSubmit => WebGUI::Form::submit( $session, { value => $i18n->get("form purchase button") }),
|
||||
error_msg => $options->{error_msg},
|
||||
hasAddedToCart => $self->{_hasAddedToCart},
|
||||
continueShoppingUrl => $self->getUrl,
|
||||
manageLink => $self->getUrl("func=manage"),
|
||||
|
|
@ -520,20 +523,65 @@ Add this subscription to the cart.
|
|||
|
||||
sub www_addToCart {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $i18n = $self->i18n;
|
||||
if ($self->canView) {
|
||||
$self->{_hasAddedToCart} = 1;
|
||||
my $form = $self->session->form;
|
||||
my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($self->session); # LATER should be createTemp
|
||||
my $imageStorageId = $form->process('formImage', 'image', $imageStorage->getId);
|
||||
my $cartInfo = {
|
||||
adtitle => $form->process('formTitle'),
|
||||
link => $form->process('formLink','url'),
|
||||
clicks => $form->process('formClicks','integer'),
|
||||
impressions => $form->process('formImpressions','integer'),
|
||||
adId => $form->process('formAdId'),
|
||||
image => $imageStorageId,
|
||||
};
|
||||
$self->addToCart($cartInfo);
|
||||
my $form = $session->form;
|
||||
my @errors;
|
||||
#my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($session); # LATER should be createTemp
|
||||
my $imageStorageId = $form->process('formImage', 'image'); # , $self->getOptions->{image});
|
||||
my $imageStorage = WebGUI::Storage->get($session,$imageStorageId);
|
||||
my $code;
|
||||
if( not defined $imageStorage ) { $code = 1; }
|
||||
elsif( $imageStorage->getErrorCount > 0 ) { $code = 2; }
|
||||
elsif( scalar(@{$imageStorage->getFiles}) == 0 ) { $code = 3; }
|
||||
elsif( $imageStorage->isImage((@{$imageStorage->getFiles})[0]) ) { $code = 4; }
|
||||
if( not defined $imageStorage
|
||||
or $imageStorage->getErrorCount > 0
|
||||
or scalar(@{$imageStorage->getFiles}) == 0
|
||||
# or $imageStorage->isImage((@{$imageStorage->getFiles})[0]) # not currently working
|
||||
) {
|
||||
push @errors, $i18n->get('form error no image') . $code . eval { (@{$imageStorage->getFiles})[0] } ;
|
||||
}
|
||||
my $title = $form->process('formTitle');
|
||||
if($title eq '' ) {
|
||||
push @errors, $i18n->get('form error no title');
|
||||
}
|
||||
my $link = $form->process('formLink','url');
|
||||
if($link eq '' ) {
|
||||
push @errors, $i18n->get('form error no link');
|
||||
}
|
||||
my $adId = $self->get('adSpace');
|
||||
my $adSpace = WebGUI::AdSpace->new($session,$adId);
|
||||
my $clicks = $form->process('formClicks','integer');
|
||||
if($clicks < $adSpace->get('minimumClicks') ) {
|
||||
push @errors, sprintf($i18n->get('form error min clicks'), $adSpace->get('minimumClicks'));
|
||||
}
|
||||
my $impressions = $form->process('formImpressions','integer');
|
||||
if($impressions < $adSpace->get('minimumImpressions') ) {
|
||||
push @errors, sprintf($i18n->get('form error min impressions'), $adSpace->get('minimumImpressions'));
|
||||
}
|
||||
if( @errors == 0 ) {
|
||||
$self->{_hasAddedToCart} = 1;
|
||||
$self->addToCart({
|
||||
adtitle => $title,
|
||||
link => $link,
|
||||
clicks => $clicks,
|
||||
impressions => $impressions,
|
||||
adId => $adId,
|
||||
image => $imageStorageId,
|
||||
});
|
||||
} else {
|
||||
$self->applyOptions({
|
||||
adtitle => $title,
|
||||
link => $link,
|
||||
clicks => $clicks,
|
||||
impressions => $impressions,
|
||||
adId => $adId,
|
||||
image => $imageStorageId,
|
||||
error_msg => join( '<br>', @errors ),
|
||||
});
|
||||
}
|
||||
}
|
||||
return $self->www_view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,8 +173,11 @@ returns true is the client/agent is a spider/indexer or some other non-human int
|
|||
sub requestNotViewed {
|
||||
|
||||
my $self = shift;
|
||||
return $self->clientIsSpider()
|
||||
|| $self->callerIsSearchSite();
|
||||
return $self->clientIsSpider();
|
||||
# || $self->callerIsSearchSite(); # this part is currently left out because
|
||||
# it has minimal effect and does not manage
|
||||
# IPv6 addresses. it may be useful in the
|
||||
# future though
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -225,6 +225,36 @@ our $I18N = {
|
|||
context => q|Thank the customer after adding the item to the cart.|
|
||||
},
|
||||
|
||||
'form error no image' => {
|
||||
message => q|Please assign an image for this ad.|,
|
||||
lastUpdated => 0,
|
||||
context => q|remind the user to upload an image for the ad.|
|
||||
},
|
||||
|
||||
'form error no title' => {
|
||||
message => q|Please enter the title for this ad.|,
|
||||
lastUpdated => 0,
|
||||
context => q|Remind the user to enter a title for the ad.|
|
||||
},
|
||||
|
||||
'form error no link' => {
|
||||
message => q|Please enter a valid URL for this ad.|,
|
||||
lastUpdated => 0,
|
||||
context => q|Remind the user to enter a valid URL for the ad.|
|
||||
},
|
||||
|
||||
'form error min clicks' => {
|
||||
message => q|You must purchase at least %d clicks for this adSpace.|,
|
||||
lastUpdated => 0,
|
||||
context => q|Remind the user to that they must purchase a minimum number of clicks, use '%d' to indicate the minimum number of clicks.|
|
||||
},
|
||||
|
||||
'form error min impressions' => {
|
||||
message => q|You must purchase at least %d impressions for this adSpace.|,
|
||||
lastUpdated => 0,
|
||||
context => q|Remind the user to that they must purchase a minimum number of impressions, use '%d' to indicate the minimum number of impressions.|
|
||||
},
|
||||
|
||||
# 'TODO' => {
|
||||
# message => q|TODO|,
|
||||
# lastUpdated => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue