[Bast-commits] r9871 - in ironman/IronMan-Web/trunk: .
lib/IronMan/Web/Controller root
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Sat Apr 16 21:06:56 GMT 2011
Author: dhoss
Date: 2011-04-16 21:06:56 +0000 (Sat, 16 Apr 2011)
New Revision: 9871
Modified:
ironman/IronMan-Web/trunk/Makefile.PL
ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm
ironman/IronMan-Web/trunk/root/retrieve_key.tt
ironman/IronMan-Web/trunk/root/update_feed.tt
Log:
added error checks
Modified: ironman/IronMan-Web/trunk/Makefile.PL
===================================================================
--- ironman/IronMan-Web/trunk/Makefile.PL 2011-04-16 20:34:01 UTC (rev 9870)
+++ ironman/IronMan-Web/trunk/Makefile.PL 2011-04-16 21:06:56 UTC (rev 9871)
@@ -24,7 +24,7 @@
requires 'YAML::XS';
requires 'IronMan::Schema';
requires 'Term::Prompt';
-
+requires 'Try::Tiny';
# We need DateTime::Format::SQLite for script/import_csv.pl if using SQLite
recommends 'DateTime::Format::SQLite';
Modified: ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm
===================================================================
--- ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm 2011-04-16 20:34:01 UTC (rev 9870)
+++ ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm 2011-04-16 21:06:56 UTC (rev 9871)
@@ -6,6 +6,7 @@
use Email::Valid;
use DateTime;
use XML::OPML;
+use Try::Tiny;
use base 'Catalyst::Controller::reCAPTCHA';
#
@@ -151,30 +152,34 @@
sub update_feed : Local Args(0) {
my ( $self, $c ) = @_;
- if ( $c->req->param('url')
- && $c->req->param('email')
- && $c->req->param('id') )
- {
+ if ( $c->req->param ) {
+ if ( $c->req->param('url')
+ && $c->req->param('email')
+ && $c->req->param('id') )
+ {
- my $feed = $c->model('FeedDB::Feed')->find(
- {
- id => $c->req->param('id'),
- email => $c->req->param('email')
- }
- );
+ my $feed = $c->model('FeedDB::Feed')->find(
+ {
+ id => $c->req->param('id'),
+ email => $c->req->param('email')
+ }
+ );
- if ( defined $feed ) {
+ if ( defined $feed ) {
- $feed->update( { url => $c->req->param('url') } )
- or die "Error: $!";
- $c->stash( updated => 1 );
+ $feed->update( { url => $c->req->param('url') } )
+ or die "Error: $!";
+ $c->stash( updated => 1 );
- } else {
+ } else {
- $c->stash( error => "No such user" );
+ $c->stash( error => "No such user" );
+ }
+
+ } else {
+ $c->stash( error => "All fields required." );
}
-
}
}
@@ -187,39 +192,55 @@
sub retrieve_key : Local Args(0) {
my ( $self, $c ) = @_;
my $email = $c->req->param('email');
- if ( $email ) {
- my $feed =
- $c->model('FeedDB::Feed')->find( { owner => $email } );
- if ( defined $feed ) {
- $c->log->info( 'found key: ' . $feed->id );
- $c->stash(
- email => {
- to => $email,
- from => 'me at dhoss.net',
- subject => 'Your IronMan Blog Key',
- body => qq{
+ if ( $c->req->param ) {
+ if ($email) {
+ my $feed;
+ ## don't notify whether email address was found,
+ ## brute force could theoretically give a list of valid emails
+ ## contained here.
+ try {
+ $feed = $c->model('FeedDB::Feed')->find( { owner => $email } );
+ $c->log->info( 'found key: ' . $feed->id );
+ $c->stash(
+ email => {
+ to => $email,
+ from => 'me at dhoss.net',
+ subject => 'Your IronMan Blog Key',
+ body => qq{
Hello } . $feed->owner . qq{,
You or someone else has requested your IronMan Blog key.
Here it is: } . $feed->id . qq{
Regards,
The IronMan Blogging Tech Monkies
},
- },
- );
+ },
+ );
- $c->forward( $c->view('Email') );
+ $c->forward( $c->view('Email') );
- if ( scalar( @{ $c->error } ) ) {
+ if ( scalar( @{ $c->error } ) ) {
- $c->stash( error => $c->error );
+ $c->stash( error => $c->error );
- } else {
+ }
- $c->stash(
+ }
+ finally {
+ if (@_) {
+ $c->log->error( "Original error: @_" );
+ $c->log->error( 'email ' . $email . ' not found' );
+ }
+ $c->stash(
sent => 1,
- to => $feed->owner );
- }
+ to => $email
+ );
+ };
+
+ } else {
+
+ $c->stash( error => "No email specified" );
+
}
}
}
Modified: ironman/IronMan-Web/trunk/root/retrieve_key.tt
===================================================================
--- ironman/IronMan-Web/trunk/root/retrieve_key.tt 2011-04-16 20:34:01 UTC (rev 9870)
+++ ironman/IronMan-Web/trunk/root/retrieve_key.tt 2011-04-16 21:06:56 UTC (rev 9871)
@@ -1,4 +1,6 @@
-[% UNLESS error %]
+[% IF error %]
+[% error %]
+[% END %]
[% IF sent %]
<p>Your key is en route to [% to %]</p>
[% END %]
@@ -7,6 +9,3 @@
<p>Your email: <input type="text" name="email" /></p>
<p><input type="submit" value="Get it" /></p>
</form>
-[% ELSE %]
-[% error %]
-[% END %]
Modified: ironman/IronMan-Web/trunk/root/update_feed.tt
===================================================================
--- ironman/IronMan-Web/trunk/root/update_feed.tt 2011-04-16 20:34:01 UTC (rev 9870)
+++ ironman/IronMan-Web/trunk/root/update_feed.tt 2011-04-16 21:06:56 UTC (rev 9871)
@@ -1,14 +1,12 @@
-[% UNLESS error %]
+[% IF error %]
+[% error %]
+[% END %]
[% IF updated %]
<p>Feed url successfully updated</p>
[% END %]
-<p>Welcome, [% owner %]</p>
<form method="post" action="">
<p>Your email: <input type="text" name="email" /></p>
<p>Your user key: (<a href="/retrieve_key">forgot it?</a>): <input type="text" name="id" /></p>
<p>New url for feed (current is: [% feed %]): <input type="text" name="url" /></p>
<p><input type="submit" value="Update feed url" /></p>
</form>
-[% ELSE %]
-[% error %]
-[% END %]
More information about the Bast-commits
mailing list