[Bast-commits] r5428 - trunk/PhotoOp/lib/PhotoOp/Controller
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Sat Feb 7 18:20:07 GMT 2009
Author: castaway
Date: 2009-02-07 18:20:07 +0000 (Sat, 07 Feb 2009)
New Revision: 5428
Modified:
trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm
Log:
Allow public viewing of images with tag "public", thumbnails too
Modified: trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm
===================================================================
--- trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm 2009-02-07 17:59:04 UTC (rev 5427)
+++ trunk/PhotoOp/lib/PhotoOp/Controller/Root.pm 2009-02-07 18:20:07 UTC (rev 5428)
@@ -50,21 +50,42 @@
# $c->log->_dump(\%ENV);
# $c->log->info("User: $ENV{REMOTE_USER}");
# eval {
- $c->authorization_required( realm => 'PhotoOp');
+ if($c->action ne 'publicthumb' && $c->action ne 'publicimage') {
+# $c->authorization_required( realm => 'PhotoOp');
+ $c->detach('authen');
+# $c->stash->{template} = 'login';
+ return 0 if !$c->user_exists;
+ }
# };
- $c->log->debug("ERRORS") if ($@);
- $c->log->_dump($@) if($@);
- $c->log->_dump($c->error) if($c->error);
+# $c->log->debug("ERRORS") if ($@);
+# $c->log->_dump($@) if($@);
+# $c->log->_dump($c->error) if($c->error);
# $c->authorization_basic( realm => 'PhotoOp');
- unless($c->user_exists)
+# if(!$c->user_exists && $c->action ne 'public')
+# {
+# $c->stash->{message} = 'Not logged in.';
+# $c->stash->{template} = 'login';
+# return 0;
+# }
+
+ $c->stash->{authenticated} = 1 if($c->model('MyFlickr')->is_authenticated);
+ return 1;
+}
+
+sub authen : Private {
+ my ($self, $c) = @_;
+
+ $c->authorization_required( realm => 'PhotoOp');
+
+ if(!$c->user_exists)
{
$c->stash->{message} = 'Not logged in.';
- $c->stash->{template} = 'login';
+ $c->log->debug("authen: no user; template ". $c->stash->{template});
return 0;
}
- $c->stash->{authenticated} = 1 if($c->model('MyFlickr')->is_authenticated);
+ $c->log->debug("authen: user; template ". $c->stash->{template});
return 1;
}
@@ -113,9 +134,9 @@
@args = $c->stash->{current_dir} if !@args;
my $file = file('/', @args);
$c->res->redirect($c->uri_for('/path', $file->dir)) if(!-f $file);
- my $image = $c->model('Image')->new({file => $file});
+ my $image = $c->stash->{image} || $c->model('Image')->new({file => $file});
+
-
$self->filedialog($c, $file);
for my $sibling ('left', 'right') {
if ($c->stash->{"${sibling}_type"} eq 'editfile') {
@@ -151,7 +172,7 @@
$c->stash->{edittags} = { map {$_ => 1} @{ $c->config->{edittags} } };
$c->stash->{showtags} = $c->config->{showtags};
- $c->stash->{image} = $image;
+ $c->stash->{image} ||= $image;
$c->stash->{googlekey} = $self->google_key($c);
$c->stash->{rotation} = [{ display => '+90', rotate => '-9'},
{ display => '-90', rotate => '-2'},
@@ -293,6 +314,29 @@
}
+sub publicimage : Local
+{
+ my ($self, $c) = @_;
+
+ my @args = @{$c->req->args};
+ @args = $c->stash->{current_dir} if !@args;
+ my $file = file('/', @args);
+ if(!-f "$file")
+ {
+ $c->stash->{message} = "No such file: $file\n";
+ $c->stash->{template} = 'login.tt';
+ return 1;
+ }
+
+ if(!$self->is_public($c, $file)) {
+ $c->stash->{template} = 'login.tt';
+ return $c->detach('authen');
+ }
+
+ $c->log->debug("publicimage: is_public; template ". $c->stash->{template});
+ return $c->forward('displayfile');
+}
+
sub displayfile : Local
{
my ($self, $c) = @_;
@@ -346,6 +390,27 @@
# return $c->stash->{dirlist} || '<b>No such directory</b>';
# }
+sub publicthumb : Local
+{
+ my ($self, $c) = @_;
+
+ my @args = @{$c->req->args};
+ @args = $c->stash->{current_dir} if !@args;
+ my $file = file('/', @args);
+ if(!-f "$file")
+ {
+ $c->stash->{message} = "No such file: $file\n";
+ return 1;
+ }
+
+ if(!$self->is_public($c, $file)) {
+ $c->stash->{template} = 'login.tt';
+ return $c->detach('authen');
+ }
+
+ $c->forward('thumbnail');
+}
+
sub thumbnail : Local
{
my ($self, $c) = @_;
@@ -400,10 +465,12 @@
my ($self, $c, $file) = @_;
print STDERR "is_private: ", caller(), "\n";
- my $image = $c->model('Image')->new({file => $file});
+ my $image = $c->stash->{image} || $c->model('Image')->new({file => $file});
+ $c->stash->{image} ||= $image;
$c->log->debug("Body length is: " . length( $c->response->body ));
if(!$c->check_user_roles('admin') && $image->{tags}{UserComment} &&
- $image->{tags}{UserComment} =~ /\bprivate\b/i)
+ ( $image->{tags}{UserComment} =~ /\bprivate\b/i ||
+ $image->{tags}{'IPTC:Keywords'} =~ /\bprivate\b/i))
{
$c->res->content_type('text/plain');
$c->res->body("This file has been tagged private, sorry ;)");
@@ -414,6 +481,24 @@
return 0;
}
+sub is_public
+{
+ my ($self, $c, $file) = @_;
+
+ print STDERR "is_public: ", caller(), "\n";
+ my $image = $c->stash->{image} || $c->model('Image')->new({file => $file});
+ $c->stash->{image} ||= $image;
+ $c->log->debug("Body length is: " . length( $c->response->body ));
+ if($image->{tags}{UserComment} &&
+ ( $image->{tags}{UserComment} =~ /\bpublic\b/i ||
+ $image->{tags}{'IPTC:Keywords'} =~ /\bpublic\b/i))
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
sub google_key
{
my ($self, $c) = @_;
@@ -449,8 +534,11 @@
sub end : ActionClass('RenderView')
{
-# my ($self, $c) = shift;
+ my ($self, $c) = @_;
# $c->log->_dump($c->res);
+ if(!$c->user_exists) {
+ $c->stash->{template} = 'login.tt';
+ }
}
=head1 AUTHOR
More information about the Bast-commits
mailing list