| 1 | package Puzzle::Page; | ||
| 2 | |||
| 3 | our $VERSION = '0.02'; | ||
| 4 | |||
| 5 | use Params::Validate qw(:types); | ||
| 6 | use base 'Class::Container'; | ||
| 7 | __PACKAGE__->valid_params( | ||
| 8 | bottom => { isa => 'Puzzle::Block'} , | ||
| 9 | center => { isa => 'Puzzle::Block'} , | ||
| 10 | left => { isa => 'Puzzle::Block'} , | ||
| 11 | right => { isa => 'Puzzle::Block'} , | ||
| 12 | top => { isa => 'Puzzle::Block'} , | ||
| 13 | ); | ||
| 14 | |||
| 15 | __PACKAGE__->contained_objects ( | ||
| 16 | bottom => { class => 'Puzzle::Block', delayed => 0 }, | ||
| 17 | center => 'Puzzle::Block', | ||
| 18 | left => { class => 'Puzzle::Block', delayed => 0 }, | ||
| 19 | right => { class => 'Puzzle::Block', delayed => 0 }, | ||
| 20 | top => { class => 'Puzzle::Block', delayed => 0 }, | ||
| 21 | ); | ||
| 22 | |||
| 23 | |||
| 24 | # all new valid_params are read&write methods | ||
| 25 | use HTML::Mason::MethodMaker( | ||
| 26 | read_only => [ qw(bottom center left right top) ], | ||
| 27 | ); | ||
| 28 | |||
| 29 | sub process { | ||
| 30 | my $self = shift; | ||
| 31 | my $puzzle = $self->container; | ||
| 32 | my $m = $puzzle->_mason; | ||
| 33 | # $self->container->post->_set({$self->container->_mason->request_args}); | ||
| 34 | my $nextComp = $m->fetch_next; | ||
| 35 | #$puzzle->log->debug(( caller(0) )[3] . ": component " . $nextComp->path); | ||
| 36 | if (eval {$nextComp->attr('gid')} && | ||
| 37 | $self->container->cfg->gids($nextComp->attr('gids')) && | ||
| 38 | !$puzzle->session->auth->check) { | ||
| 39 | # l'utente non ha accesso alla pagina. Mostro la pagina di login | ||
| 40 | $self->_show_login; | ||
| 41 | $self->center->process_as_login; | ||
| 42 | } else { | ||
| 43 | # accesso alla pagina consentito | ||
| 44 | $self->center->comp($nextComp); | ||
| 45 | $self->center->process_as_center; | ||
| 46 | if ($self->center->isa_error) { | ||
| 47 | $self->container->session->save; | ||
| 48 | # visto che e' un errore mason, lo rilancio | ||
| 49 | HTML::Mason::Exceptions::rethrow_exception($self->center->html); | ||
| 50 | return; | ||
| 51 | } elsif ($self->center->direct_output) { | ||
| 52 | # interrompo tutto | ||
| 53 | return; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | # SE SERVE, RIVALIDO l'UTENTE | ||
| 57 | # VALUTARE SE LE DUE VERIFICHE QUI E PRIMA NON SI POSSANO INGLOBARE IN | ||
| 58 | # UNA UNICA | ||
| 59 | unless ($puzzle->session->auth->check) { | ||
| 60 | # l'utente non ha accesso alla pagina. Mostro la pagina di login | ||
| 61 | $self->center->comp_path($puzzle->cfg->login); | ||
| 62 | $self->center->process_as_login; | ||
| 63 | } | ||
| 64 | if ($puzzle->cfg->frames && | ||
| 65 | $puzzle->args->print ne '1' && $puzzle->cfg->base) { | ||
| 66 | #@$puzzle->log->debug(( caller(0) )[3] . ": Print page with frames"); | ||
| 67 | foreach (qw/top left right bottom/) { | ||
| 68 | if ($puzzle->cfg->{"frame_${_}_file"} ne '') { | ||
| 69 | $self->$_->comp_path($puzzle->cfg->{"frame_${_}_file"}); | ||
| 70 | $self->$_->process; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } else { | ||
| 74 | #$puzzle->log->debug(( caller(0) )[3] . ": Set page without frames because: cfg->frames is " . | ||
| 75 | # $puzzle->cfg->frames . " and args->print is " . $puzzle->args->print . " and cfg->base is " . | ||
| 76 | # $puzzle->cfg->base); | ||
| 77 | $self->center->{direct_output} = 1; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | sub body { | ||
| 82 | my $self = shift; | ||
| 83 | return $self->center->body; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub headers { | ||
| 87 | my $self = shift; | ||
| 88 | my $ret = ''; | ||
| 89 | my @frames = qw/center top left right bottom/; | ||
| 90 | foreach (@frames) { | ||
| 91 | $ret .= $self->$_->headers; | ||
| 92 | } | ||
| 93 | return $ret; | ||
| 94 | } | ||
| 95 | |||
| 96 | sub body_attributes { | ||
| 97 | my $self = shift; | ||
| 98 | return $self->center->body_attributes; | ||
| 99 | } | ||
| 100 | |||
| 101 | sub title { | ||
| 102 | my $self = shift; | ||
| 103 | return $self->center->title; | ||
| 104 | } | ||
| 105 | |||
| 106 | sub _show_login { | ||
| 107 | my $self = shift; | ||
| 108 | my $puzzle = $self->container; | ||
| 109 | #$puzzle->args->page($ENV{SCRIPT_NAME}); | ||
| 110 | #$puzzle->args->group(join(' oppure ',@{$puzzle->cfg->gids} )); | ||
| 111 | $self->center->comp_path($puzzle->cfg->login); | ||
| 112 | } | ||
| 113 | 1; |