site/cgi-bin/modules/BSE/UI/FileProgress.pm
site/cgi-bin/modules/BSE/UI/Formmail.pm
site/cgi-bin/modules/BSE/UI/Image.pm
+site/cgi-bin/modules/BSE/UI/Interest.pm
site/cgi-bin/modules/BSE/UI/NAdmin.pm
site/cgi-bin/modules/BSE/UI/NUser.pm
site/cgi-bin/modules/BSE/UI/Page.pm
use strict;
use FindBin;
use lib "$FindBin::Bin/modules";
-use Constants qw(:shop);
-use BSE::Session;
-use BSE::Template;
-use BSE::Util::Tags;
-use BSE::Request;
+use BSE::UI;
-my $req = BSE::Request->new;
-my $cfg = $req->cfg;;
-
-my $cgi = $req->cgi;
-my $useremail = $cgi->param('email');
-unless ($useremail) {
- my $user = $req->siteuser;
- if ($user) {
- $useremail = $user->{email};
- }
-}
-unless ($useremail) {
- error_page("interest/noemail",
- "Please enter an email address, register or logon",
- 'interest/askagain');
-}
-if ($useremail !~ /.\@./) {
- error_page("interest/bademail",
- "Please enter a valid email address.",
- 'interest/askagain');
-}
-
-# in theory we have an email address at this point
-require BSE::ComposeMail;
-my $mailer = BSE::ComposeMail->new(cfg => $cfg);
-
-my $email = $cfg->entry('interest', 'notify',
- $Constants::SHOP_FROM);
-$email ||= $cfg->entry('shop', 'from');
-unless ($email) {
- print STDERR "No email configured for interest notify, set [interest].notify\n";
- return;
-}
-#
-my $product = $cgi->param('product');
-defined($product) or $product = '';
-my $product_id = $cgi->param('product_id');
-defined($product_id) or $product_id = '';
-
-my %acts;
-%acts =
- (
- $req->dyn_user_tags(),
- product => sub { $product },
- product_id => sub { $product_id },
- email => sub { $useremail },
- );
-
-my $subject = "User registered interest";
-$subject .= " in product '$product'" if $product;
-
-$mailer->send(template => 'admin/interestemail',
- acts => \%acts,
- to=>$email,
- from=>$email,
- subject=>$subject)
- or error_page('', "While sending email: ".$mailer->errstr);
-
-BSE::Template->show_page('interest/confirm', $cfg, \%acts);
-
-sub error_page {
- my ($id, $msg, $template) = @_;
-
- $msg = $cfg->entry(messages=>$id, $msg) if $id;
- $template ||= 'interest/error';
- my %acts;
- %acts =
- (
- $req->dyn_user_tags,
- msg => sub { CGI::escapeHTML($msg) },
- );
- BSE::Template->show_page($template, $cfg, \%acts);
- exit;
-}
+BSE::UI->run("BSE::UI::Interest");
--- /dev/null
+package BSE::UI::Interest;
+use strict;
+use base 'BSE::UI::Dispatch';
+use BSE::ComposeMail;
+
+our $VERSION = "1.000";
+
+my %actions =
+ (
+ interest => 1,
+ );
+
+sub actions { \%actions };
+
+sub default_action { "interest" }
+
+sub req_interest {
+ my ($self, $req) = @_;
+
+ my $cfg = $req->cfg;;
+
+ my $cgi = $req->cgi;
+ my $useremail = $cgi->param('email');
+ unless ($useremail) {
+ my $user = $req->siteuser;
+ if ($user) {
+ $useremail = $user->{email};
+ }
+ }
+ unless ($useremail) {
+ my $msg = $req->catmsg("msg:bse/interest/noemail", [],
+ "Please enter an email address, register or logon");
+ return $self->error($req, $msg, "interest/askagain");
+ }
+
+ if ($useremail !~ /.\@./) {
+ my $msg = $req->catmsg("msg:bse/interest/bademail", [],
+ "Please enter a valid email address.");
+ return $self->error($req, $msg, "interest/askagain");
+ }
+
+ # in theory we have an email address at this point
+ my $mailer = BSE::ComposeMail->new(cfg => $cfg);
+
+ my $email = $cfg->entry('interest', 'notify');
+ $email ||= $cfg->entry('shop', 'from', $Constants::SHOP_FROM);
+ unless ($email) {
+ print STDERR "No email configured for interest notify, set [interest].notify\n";
+ return;
+ }
+#
+ my $product = $cgi->param('product');
+ defined($product) or $product = '';
+ my $product_id = $cgi->param('product_id');
+ defined($product_id) or $product_id = '';
+
+ $req->set_variable(email => $useremail);
+ $req->set_variable(product => $product);
+ $req->set_variable(product_id => $product_id);
+
+ my %acts;
+ %acts =
+ (
+ $req->dyn_user_tags(),
+ product => sub { $product },
+ product_id => sub { $product_id },
+ email => sub { $useremail },
+ );
+
+ my $subject = "User registered interest";
+ $subject .= " in product '$product'" if $product;
+
+ unless ($mailer->send(template => 'admin/interestemail',
+ acts => \%acts,
+ to=>$email,
+ from=>$email,
+ subject=>$subject)) {
+ return $self->error($req, "While sending email: ".$mailer->errstr);
+ }
+
+ return $req->response('interest/confirm', \%acts);
+}
+
+1;
id: bse/
description: BSE messages
+id: bse/interest
+description: <<TEXT
+Messages displayed by interest.pl
+TEXT
+
+id: bse/interest/noemail
+description: displayed when no email address has been entered and the siteuser isn't logged in
+
+id: bse/interest/bademail
+description: displayed when the supplied email address is invalid
+
id: bse/user/
description: <<TEXT
Messages displayed by user.pl (member user registration, logon, etc)
language_code: en
priority: 0
+id: bse/interest/noemail
+message: Please enter an email address, or please logon.
+
+id: bse/interest/bademail
+message: Email address invalid.
+
id: bse/user/needlogon
message: Please enter your username
#!perl -w
use strict;
-use Test::More tests => 33;
+use Test::More tests => 34;
use_ok("BSE::Cfg");
use_ok("Squirrel::Template");
use_ok("BSE::Template");
use_ok("BSE::ImageClean");
use_ok("BSE::UI::AdminImageClean");
use_ok("BSE::UI::Thumb");
+use_ok("BSE::UI::Interest");
my $builder = Test::Builder->new;
$builder->is_passing or $builder->BAIL_OUT;