diff options
Diffstat (limited to 'lib/CatDap')
-rw-r--r-- | lib/CatDap/Controller/user.pm | 34 | ||||
-rw-r--r-- | lib/CatDap/View/TT.pm | 2 |
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/CatDap/Controller/user.pm b/lib/CatDap/Controller/user.pm index 0603217..90dbb0e 100644 --- a/lib/CatDap/Controller/user.pm +++ b/lib/CatDap/Controller/user.pm @@ -53,8 +53,8 @@ sub auto : Private { #TODO: ppolicy .... $c->stash(errors => ['Incorrect username or password']); $c->stash(template => 'index.tt'); - $c->forward('/index'); - $c->detach; + #$c->forward('/index'); + $c->detach('/user/login'); } else { #if (defined $c->user->pwdReset) { # $c->res->redirect('/user'); @@ -65,6 +65,7 @@ sub auto : Private { -cipher => 'Blowfish' ) or die $!; $c->session->{enc_password} = $cipher->encrypt($c->req->param('password') || $c->req->param('key')); + $c->stash(pages => roles2pages($c->user->roles)); $c->session->{dn} = $c->user->ldap_entry->dn; $c->session->{user} = $c->req->param('username'); $password = $c->req->param('password') || $c->req->param('key'); @@ -78,6 +79,8 @@ sub auto : Private { $password = $cipher->decrypt($c->session->{enc_password}); $c->log->info("Re-authenticating user " . $c->session->{user}); $c->authenticate({username => $c->session->{user},password => $password}); + + $c->stash(pages => roles2pages($c->user->roles)); $c->log->info($@) if $@; return 1; } @@ -186,6 +189,7 @@ sub index :Path :Args(0) { may => \@may, must => \@must, }); + $c->stash(subpages => gensubpages()); } sub add : Local { @@ -223,8 +227,10 @@ sub delete : Local : Args(2) { sub password : Local { my ( $self, $c) = @_; my ($mesg,$newpass,$cipher); + $c->stash(subpages => gensubpages()); if ( not defined $c->req->param('password') or not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) { #if ( not defined $c->req->param('newpassword1') or not defined $c->req->param('newpassword2')) { + $c->detach; } if ($c->req->param('newpassword1') eq $c->req->param('newpassword2')) { @@ -318,6 +324,30 @@ sub logout : Local { $c->res->redirect('/'); } +sub roles2pages : Private { + my @roles = @_; + my @pages; + foreach my $role (sort @roles) { + if ($role =~ /^(\w+) ?(\w*) (Admin)s$/) { + my $page = lc("/$3/$1$2"); + push @pages,{ page => lc("/$3/$1$2"), title => "$1 $2 $3"}; + } + } + return \@pages; +} + +sub gensubpages : Private { + my ($type) = @_; + my @subpagenames; + @subpagenames = ( + { page => './', title => "Edit"}, + { page => 'password', title => "Change password"}, + ); + return \@subpagenames; +} + + + =head1 AUTHOR Buchan Milne diff --git a/lib/CatDap/View/TT.pm b/lib/CatDap/View/TT.pm index 0cd6acb..f63d775 100644 --- a/lib/CatDap/View/TT.pm +++ b/lib/CatDap/View/TT.pm @@ -8,6 +8,8 @@ use base 'Catalyst::View::TT'; __PACKAGE__->config( TEMPLATE_EXTENSION => '.tt', render_die => 1, + WRAPPER => 'template/wrapper', + PRE_PROCESS => 'template/pre', ); =head1 NAME |