]> git.imager.perl.org - bse.git/commitdiff
update interest.pl to more modern style
authorTony Cook <tony@develop-help.com>
Thu, 11 Dec 2014 06:04:49 +0000 (17:04 +1100)
committerTony Cook <tony@develop-help.com>
Thu, 11 Dec 2014 06:04:49 +0000 (17:04 +1100)
MANIFEST
site/cgi-bin/interest.pl
site/cgi-bin/modules/BSE/UI/Interest.pm [new file with mode: 0644]
site/data/db/bse_msg_base.data
site/data/db/bse_msg_defaults.data
t/t000load.t

index b889bc90879ef4b09da847edb4835d65b0621257..fc76fa278607bc3a177d9b0efff18e9e04c851a7 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -285,6 +285,7 @@ site/cgi-bin/modules/BSE/UI/Dispatch.pm
 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
index 78051c3fe74fcd5409c976597960729f0a4aa5ba..c03ff79c426d3946f267b05259f9c3248182d3b3 100755 (executable)
@@ -4,83 +4,6 @@
 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");
diff --git a/site/cgi-bin/modules/BSE/UI/Interest.pm b/site/cgi-bin/modules/BSE/UI/Interest.pm
new file mode 100644 (file)
index 0000000..19bef65
--- /dev/null
@@ -0,0 +1,84 @@
+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;
index 179e383889d567fc1c580e0feb6099cfdf1f3b6d..4f05804e2fa36f7af5e2db172c36fec2294715e7 100644 (file)
@@ -3,6 +3,17 @@
 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)
index 9d6a8fc15803fb61021bfaa9725a66e40822e2ca..8cd4bc4d4bfd254538ba3dc971702546c474d323 100644 (file)
@@ -4,6 +4,12 @@
 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
 
index d1ee973335ad0583a8761fd6ea7f104981bd93e6..cf5aa24663143d8f4c0b814eb2b907202f0efed3 100644 (file)
@@ -1,6 +1,6 @@
 #!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");
@@ -34,6 +34,7 @@ use_ok("BSE::Index::BSE");
 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;