[Bast-commits] r9869 - in ironman/IronMan-Web/trunk: lib/IronMan/Web/Controller root root/inc

dhoss at dev.catalyst.perl.org dhoss at dev.catalyst.perl.org
Sat Apr 16 20:33:46 GMT 2011


Author: dhoss
Date: 2011-04-16 20:33:46 +0000 (Sat, 16 Apr 2011)
New Revision: 9869

Modified:
   ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm
   ironman/IronMan-Web/trunk/root/inc/ironman_header.tt
   ironman/IronMan-Web/trunk/root/update_feed.tt
Log:
unfucked root controller, updated ironman header to reflect update_feed link, changed update_feed action to ask for email/user key as well, and added a link to "forgot user key"

Modified: ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm
===================================================================
--- ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm	2011-04-16 19:24:06 UTC (rev 9868)
+++ ironman/IronMan-Web/trunk/lib/IronMan/Web/Controller/Root.pm	2011-04-16 20:33:46 UTC (rev 9869)
@@ -1,5 +1,4 @@
 package IronMan::Web::Controller::Root;
-
 use strict;
 use warnings;
 use Data::UUID;
@@ -30,33 +29,42 @@
 =head2 auto
 
 =cut
+
 sub auto : Private {
-    my ( $self, $c ) = @_;
+  my ( $self, $c ) = @_;
 
-    $c->stash->{'feeds'} = $c->model('FeedDB::Feed')->search({ 'link' => \'IS NOT NULL'});
-    $c->stash->{'branding'} = $c->config()->{'branding'};
+  $c->stash->{'feeds'} =
+    $c->model('FeedDB::Feed')->search( { 'link' => \'IS NOT NULL' } );
+  $c->stash->{'branding'} = $c->config()->{'branding'};
 }
 
-
 =head2 index
 
 =cut
 
-sub index :Path :Args(0) {
-    my ( $self, $c ) = @_;
+sub index : Path : Args(0) {
+  my ( $self, $c ) = @_;
 
-    my $posts = $c->model('FeedDB::Post')->search({},{
-        'order_by' => \'posted_on DESC',
-        'rows' => $c->config->{'frontpage_entries'} + 1,
-    });
+  my $posts = $c->model('FeedDB::Post')->search(
+    {},
+    {
+      'order_by' => \'posted_on DESC',
+      'rows'     => $c->config->{'frontpage_entries'} + 1,
+    }
+  );
 
-    $c->stash( 'posts' => $posts );
+  $c->stash( 'posts' => $posts );
 
-    my $next_post = ($posts->all)[-1];
-    
-    my $next_post_date = $next_post->posted_on;
-    my $next_post_url = $c->uri_for_action('archive/day', $next_post_date->year, $next_post_date->month, $next_post_date->day ). '#' . $next_post->post_id;
-    $c->stash( 'older_url' => $next_post_url );
+  my $next_post = ( $posts->all )[-1];
+
+  my $next_post_date = $next_post->posted_on;
+  my $next_post_url  = $c->uri_for_action(
+    'archive/day',          $next_post_date->year,
+    $next_post_date->month, $next_post_date->day
+    )
+    . '#'
+    . $next_post->post_id;
+  $c->stash( 'older_url' => $next_post_url );
 }
 
 =head2 new_feed
@@ -64,95 +72,109 @@
 =cut
 
 sub new_feed : Local {
-    my ($self, $c) = @_;
-    
-    my $url = $c->req->param('url');
-    my $email = $c->req->param('email');
-    my $email_conf = $c->req->param('email_2');
-    my $title = $c->req->param('title');
+  my ( $self, $c ) = @_;
 
-    $c->stash( params => $c->req->params);
-    $c->forward('captcha_get');
+  my $url        = $c->req->param('url');
+  my $email      = $c->req->param('email');
+  my $email_conf = $c->req->param('email_2');
+  my $title      = $c->req->param('title');
 
-    return 1 if(!%{ $c->req->params });
+  $c->stash( params => $c->req->params );
+  $c->forward('captcha_get');
 
-    my $errors = [];
-    my $feed = IronMan::Feeds::verify_feed_data($title, $url, $email, $email_conf, $errors);
-    if(!$feed || @$errors) {
-        $c->log->_dump($errors);
-        $c->stash( errors => $errors);
-        return 1;
-    }
-    if(!$c->forward('captcha_check')) {
-        $c->log->_dump($c->stash->{recaptcha_error});
-        $c->stash( errors => ['reCAPTCHA failed']);
-        return 1;
-    }
+  return 1 if ( !%{ $c->req->params } );
 
-    $c->log->debug("input ok");
+  my $errors = [];
+  my $feed =
+    IronMan::Feeds::verify_feed_data( $title, $url, $email, $email_conf,
+    $errors );
+  if ( !$feed || @$errors ) {
+    $c->log->_dump($errors);
+    $c->stash( errors => $errors );
+    return 1;
+  }
+  if ( !$c->forward('captcha_check') ) {
+    $c->log->_dump( $c->stash->{recaptcha_error} );
+    $c->stash( errors => ['reCAPTCHA failed'] );
+    return 1;
+  }
 
-    ## verify_feed_data attempts to find the first feed in the given page, if it is not a feed
-    $url = $feed->{feed};
-    $c->stash(feed_url => $url);
-    
-    my ($res, $fdb) = $c->model('FeedDB::Feed')->add_new_blog(title => $title, 
-                                                              url => $url, 
-                                                              email => $email);
+  $c->log->debug("input ok");
 
-    if(!$res) {
-        $c->stash(existed => 1);
-        $c->log->debug("$url already exists, id: " . $fdb->id);
-        return 1;
-    }
-    
-    $c->stash(inserted => $fdb->id);
+  ## verify_feed_data attempts to find the first feed in the given page, if it is not a feed
+  $url = $feed->{feed};
+  $c->stash( feed_url => $url );
+
+  my ( $res, $fdb ) = $c->model('FeedDB::Feed')->add_new_blog(
+    title => $title,
+    url   => $url,
+    email => $email
+  );
+
+  if ( !$res ) {
+    $c->stash( existed => 1 );
+    $c->log->debug( "$url already exists, id: " . $fdb->id );
+    return 1;
+  }
+
+  $c->stash( inserted => $fdb->id );
 }
 
 #Display OPML showing the feeds.
 sub opml : Local Args(0) {
-    my ( $self, $c ) = @_;
+  my ( $self, $c ) = @_;
 
-    my $opml = new XML::OPML(version => "1.1");
+  my $opml = new XML::OPML( version => "1.1" );
 
-    $opml->head(
-        title => 'all.things.per.ly',
-        dateCreated => DateTime->now(),
-    ); 
+  $opml->head(
+    title       => 'all.things.per.ly',
+    dateCreated => DateTime->now(),
+  );
 
-    $c->res->content_type('application/xml');
+  $c->res->content_type('application/xml');
 
-    foreach my $feed ($c->model('FeedDB::Feed')->all) {
-        $opml->add_outline( 
-            'title'     => $feed->title,
-            'xmlUrl'    => $feed->url,
-        );
-    }
+  foreach my $feed ( $c->model('FeedDB::Feed')->all ) {
+    $opml->add_outline(
+      'title'  => $feed->title,
+      'xmlUrl' => $feed->url,
+    );
+  }
 
-    $c->res->body($opml->as_string);
+  $c->res->body( $opml->as_string );
 }
 
-
 =head2 update_feed
 
 Update a feed give a user's unique key
 
 =cut
 
-sub update_feed : Local Args(1) {
-  my ($self, $c, $id) = @_;
-  my $feed = $c->model('FeedDB::Feed')->find({ id => $id });
-  if ( defined $feed ) {
-    $c->stash( 
-      owner => $feed->owner,
-      feed  => $feed->url,
+sub update_feed : Local Args(0) {
+  my ( $self, $c ) = @_;
+  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')
+      }
     );
-    if ( $c->req->param('url') ) {
-      $feed->update({ url => $c->req->param('url') })
+
+    if ( defined $feed ) {
+
+      $feed->update( { url => $c->req->param('url') } )
         or die "Error: $!";
       $c->stash( updated => 1 );
+
+    } else {
+
+      $c->stash( error => "No such user" );
+
     }
-  } else {
-    $c->stash( error => "No such user" );
+
   }
 }
 
@@ -162,20 +184,16 @@
 
 =cut 
 
-sub end : ActionClass('RenderView') {
+  sub end : ActionClass('RenderView') {
     my ( $self, $c ) = @_;
 
-    $c->stash(current_view => 'RSS') if (
-        ($c->req->param('feed') && $c->req->param('feed') eq 'rss') || 
-        ($c->req->param('feed') && $c->req->param('feed') eq 'RSS') || 
-        ($c->req->param('feed') && $c->req->param('feed') eq 'atom')
-    );
+    $c->stash( current_view => 'RSS' )
+      if ( ( $c->req->param('feed') && $c->req->param('feed') eq 'rss' )
+      || ( $c->req->param('feed') && $c->req->param('feed') eq 'RSS' )
+      || ( $c->req->param('feed') && $c->req->param('feed') eq 'atom' ) );
 
+  }
 
-
-}
-
-
 =head1 AUTHOR
 
 Catalyst developer
@@ -187,4 +205,4 @@
 
 =cut
 
-1;
+  1;

Modified: ironman/IronMan-Web/trunk/root/inc/ironman_header.tt
===================================================================
--- ironman/IronMan-Web/trunk/root/inc/ironman_header.tt	2011-04-16 19:24:06 UTC (rev 9868)
+++ ironman/IronMan-Web/trunk/root/inc/ironman_header.tt	2011-04-16 20:33:46 UTC (rev 9869)
@@ -3,7 +3,7 @@
         <a href="/new_feed"><img src="http://enlightenedperl.org/images/ironsignup.png" alt="signup banner" /></a><br />
         <a href="/new_feed">Join the program</a>&nbsp;|&nbsp;
         <a href="http://www.enlightenedperl.org/ironman.html">Learn about the program</a>&nbsp;|&nbsp;
-
+        <a href="/update_feed">update your feed URL (current users)</a>&nbsp;|&nbsp;
         <a href="mailto:ironman at shadowcat.co.uk">Report a problem</a>
       </p>
       <p>

Modified: ironman/IronMan-Web/trunk/root/update_feed.tt
===================================================================
--- ironman/IronMan-Web/trunk/root/update_feed.tt	2011-04-16 19:24:06 UTC (rev 9868)
+++ ironman/IronMan-Web/trunk/root/update_feed.tt	2011-04-16 20:33:46 UTC (rev 9869)
@@ -4,6 +4,8 @@
 [% 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>




More information about the Bast-commits mailing list