[Jifty-commit] r4196 - in apps/CASPlus/trunk: lib/CASPlus
lib/CASPlus/Action
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Oct 2 18:15:00 EDT 2007
Author: sterling
Date: Tue Oct 2 18:15:00 2007
New Revision: 4196
Modified:
apps/CASPlus/trunk/ (props changed)
apps/CASPlus/trunk/lib/CASPlus/Action/Login.pm
apps/CASPlus/trunk/lib/CASPlus/Action/LoginCheck.pm
apps/CASPlus/trunk/lib/CASPlus/Dispatcher.pm
Log:
r12816 at dynpc145: andrew | 2007-10-02 17:14:08 -0500
Refactored the way various actions are called so that things are a little more Jifty-friendly and the nav gets correctly generated on every request.
Modified: apps/CASPlus/trunk/lib/CASPlus/Action/Login.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Action/Login.pm (original)
+++ apps/CASPlus/trunk/lib/CASPlus/Action/Login.pm Tue Oct 2 18:15:00 2007
@@ -94,6 +94,10 @@
my $password = $self->argument_value('password');
my $service = $self->argument_value('service');
+ # Always pass back the service URL and warn setting so we don't forget it
+ $self->result->content( service => $service );
+ $self->result->content( warn => $warn );
+
if ($lt eq 'I AM ROBOT') {
$lt = CASPlus::Model::LoginAttempt->new_ticket->login_ticket;
}
Modified: apps/CASPlus/trunk/lib/CASPlus/Action/LoginCheck.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Action/LoginCheck.pm (original)
+++ apps/CASPlus/trunk/lib/CASPlus/Action/LoginCheck.pm Tue Oct 2 18:15:00 2007
@@ -104,6 +104,7 @@
# XXX FIXME I assume the create works... it might not...
+ $self->result->content( service => $service );
$self->result->content(
ticket => $service_ticket->service_ticket);
$self->result->content(
Modified: apps/CASPlus/trunk/lib/CASPlus/Dispatcher.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Dispatcher.pm (original)
+++ apps/CASPlus/trunk/lib/CASPlus/Dispatcher.pm Tue Oct 2 18:15:00 2007
@@ -23,6 +23,139 @@
The following dispatcher rules are related to the CAS 2.0 protocol.
+=head2 before GET /login
+
+Performs the login check action. Calls the L<CASPlus::Action::LoginCheck> action.
+
+=cut
+
+before GET "/login" => run {
+ my $service = get 'service';
+ my $renew = get 'renew';
+ my $gateway = get 'gateway';
+
+ # Check for existing login
+ my $action = Jifty->web->new_action(
+ class => 'LoginCheck',
+ arguments => {
+ service => $service,
+ renew => $renew,
+ gateway => $gateway,
+ },
+ );
+ $action->run;
+
+ Jifty->web->response->result( login_check => $action->result );
+};
+
+=head2 before POST /login
+
+Attempts to use the post data given to log the user in. Calls teh L<CASPlus::Action::Login> action.
+
+=cut
+
+before POST '/login' => run {
+ my $username = get 'username';
+ my $password = get 'password';
+ my $lt = get 'lt';
+ my $service = get 'service';
+ my $warn = get 'warn';
+
+ # The login screen uses a standard action, find it
+ my $login = Jifty->web->new_action(
+ class => 'Login',
+ moniker => 'login',
+ arguments => {
+ username => $username,
+ password => $password,
+ lt => $lt,
+ service => $service,
+ warn => $warn,
+ },
+ );
+ $login->run;
+
+ Jifty->web->response->result( login => $login->result );
+};
+
+=head2 before /logout
+
+Perform the logout action, if logout is permitted. Calls the L<CASPlus::Action::Logout>.
+
+=cut
+
+before '/logout' => run {
+ my $logout = Jifty->web->new_action(
+ class => 'Logout',
+ arguments => {
+ service => get 'service',
+ },
+ );
+ $logout->run;
+
+ Jifty->web->response->result( logout => $logout->result );
+};
+
+=head2 before [ /validate, /serviceValidate ]
+
+Perform service ticket validation. Calls the L<CASPlus::Action::Validate> action.
+
+=cut
+
+before [ '/validate', '/serviceValidate' ] => run {
+ my $validate = Jifty->web->new_action(
+ class => 'Validate',
+ arguments => {
+ service => get 'service',
+ ticket => get 'ticket',
+ renew => get 'renew',
+ },
+ );
+ $validate->run;
+
+ Jifty->web->response->result( validate => $validate );
+};
+
+=head2 before /proxyValidate
+
+Perform proxy ticket validation. Calls the L<CASPlus::Action::ProxyValide> action.
+
+=cut
+
+before '/proxyValidate' => run {
+ my $proxy_validate = Jifty->web->new_action(
+ class => 'ProxyValidate',
+ arguments => {
+ service => get 'service',
+ ticket => get 'ticket',
+ pgtUrl => get 'pgtUrl',
+ renew => get 'renew',
+ },
+ );
+ $proxy_validate->run;
+
+ Jifty->web->response->result( proxy_validate => $proxy_validate );
+};
+
+=head2 before /proxy
+
+Performs proxy ticket creation. Calls the L<CASPlus::Action::Proxy> action.
+
+=cut
+
+before '/proxy' => run {
+ my $proxy = Jifty->web->new_action(
+ class => 'Proxy',
+ arguments => {
+ pgt => get 'pgt',
+ targetService => get 'targetService',
+ },
+ );
+ $proxy->run;
+
+ Jifty->web->response->result( proxy => $proxy );
+};
+
=head2 before **
Grants superuser access to the requester when there are no users.
@@ -236,26 +369,47 @@
=cut
-on '**' => run {
+sub _setup_nav {
+ # Setup the home link name
+ {
+ my $nav = Jifty->web->navigation;
+ if (Jifty->web->current_user->id) {
+ $nav->child( Home =>
+ url => _('/status'),
+ label => _('Status'),
+ );
+ }
+ else {
+ $nav->child( Home =>
+ url => _('/login'),
+ label => _('Login'),
+ );
+ }
+ }
# Setup the main menu for administrator
{
+ my $nav = Jifty->web->navigation;
if (Jifty->web->current_user->may_administrate) {
# Add the Administer item to main navigation
- my $nav = Jifty->web->navigation;
$nav->child( Administer =>
label => _('Administer'),
url => '/admin',
sort_order => 50,
);
}
+
+ else {
+ $nav->delete( 'Administer' );
+ }
}
# Add the profile link for logged users
{
+ my $nav = Jifty->web->navigation;
+
if (Jifty->web->current_user->id) {
- my $nav = Jifty->web->navigation;
$nav->child( MyProfile =>
label => _('My Profile'),
url => '/user/me',
@@ -268,7 +422,16 @@
sort_order => 999,
);
}
+
+ else {
+ $nav->delete( 'MyProfile' );
+ $nav->delete( 'Logout' );
+ }
}
+}
+
+on '**' => run {
+ _setup_nav();
};
=head2 ROOT
@@ -293,7 +456,7 @@
=head2 GET login
-Performs the L<CASPlus::Model::LoginCheck> to see if the user is logged. The following response may be rendered:
+Depending on the result of the L<CASPlus::Action::LoginCheck> action. The following response may be rendered:
=over
@@ -318,30 +481,17 @@
=cut
on GET 'login' => run {
- my $service = get 'service';
- my $renew = get 'renew';
- my $gateway = get 'gateway';
-
- # Check for existing login
- my $action = Jifty->web->new_action(
- class => 'LoginCheck',
- arguments => {
- service => $service,
- renew => $renew,
- gateway => $gateway,
- },
- );
- $action->run;
+ my $result = Jifty->web->response->result('login_check');
# If they had an existing login...
- if ($action->result->success) {
+ if ($result->success) {
# They've asked for a warning or did not give us a service
- if ($action->result->content('warn')) {
+ if ($result->content('warn')) {
# If a service was given, make sure to include the ticket so the
# template can give them a proper service link
- my $ticket = $action->result->content('ticket');
+ my $ticket = $result->content('ticket');
set ticket => $ticket;
# Show them the login success page
@@ -352,9 +502,10 @@
else {
# Do we have a ticket?
- if (my $ticket = $action->result->content('ticket')) {
+ if (my $ticket = $result->content('ticket')) {
# Send them back to the service with that ticket
+ my $service = $result->content('service');
redirect_with_ticket($service, $ticket);
}
@@ -362,6 +513,7 @@
else {
# Send them back with no authentication information
+ my $service = $result->content('service');
Jifty->web->_redirect($service);
}
}
@@ -377,7 +529,7 @@
=head2 POST login
-This happens when a login form is submitted. It calls the L<CASPlus::Model::Login> action. The following responses are sent based upon the result of this action:
+This happens when a login form is submitted. Depending on the result of the L<CASPlus::Model::Login> action, the following responses are sent based upon the result of this action:
=over
@@ -398,32 +550,15 @@
=cut
on POST 'login' => run {
- my $username = get 'username';
- my $password = get 'password';
- my $lt = get 'lt';
- my $service = get 'service';
- my $warn = get 'warn';
-
- # The login screen uses a standard action, find it
- my $login = Jifty->web->new_action(
- class => 'Login',
- moniker => 'login',
- arguments => {
- username => $username,
- password => $password,
- lt => $lt,
- service => $service,
- warn => $warn,
- },
- );
- $login->run;
-
- Jifty->web->response->result( login => $login->result );
+ my $result = Jifty->web->response->result( 'login' );
# On success...
- if ($login->result->success) {
- my $ticket = $login->result->content('ticket');
- set ticket => $login->result->content('ticket');
+ if ($result->success) {
+ my $ticket = $result->content('ticket');
+ set ticket => $ticket;
+
+ my $service = $result->content('service');
+ my $warn = $result->content('warn');
# If warn is given, the success screen tells them about the process
if ($warn) {
@@ -451,7 +586,7 @@
=head2 logout
-This calls the L<CASPlus::Action::Logout> action and shows a message about logging out.
+Shows the logout screen.
If L<CASPlus::Manual::Config/AllowLogout> is set to a false value, this rule pretends that it doesn't exist.
@@ -459,100 +594,58 @@
on 'logout' => run {
if (Jifty->config->app('Login')->{'AllowLogout'}) {
- my $logout = Jifty->web->new_action(
- class => 'Logout',
- arguments => {
- service => get 'service',
- },
- );
- $logout->run;
-
show '/logout';
}
+ else {
+ abort 404;
+ }
};
=head2 validate
-This calls the L<CASPlus::Action::Validate> action and renders the response using the CAS 1.0 protocol format.
+This renders the service ticket validation response using the CAS 1.0 protocol format.
=cut
on 'validate' => run {
- my $validate = Jifty->web->new_action(
- class => 'Validate',
- arguments => {
- service => get 'service',
- ticket => get 'ticket',
- renew => get 'renew',
- },
- );
- $validate->run;
-
- set result => $validate->result;
+ my $result = Jifty->web->response->result('validate');
+ set result => $result;
show '/validate';
};
=head2 serviceValidate
-Calls the L<CASPlus::Action::Validate> action and returns the CAS 2.0 protocol response.
+This returns the CAS 2.0 protocol response for service ticket validation.
=cut
on 'serviceValidate' => run {
- my $validate = Jifty->web->new_action(
- class => 'Validate',
- arguments => {
- service => get 'service',
- ticket => get 'ticket',
- pgtUrl => get 'pgtUrl',
- renew => get 'renew',
- },
- );
- $validate->run;
-
- set result => $validate->result;
+ my $result = Jifty->web->response->result('validate');
+ set result => $result;
show '/serviceValidate';
};
=head2 proxyValidate
-Runs L<CASPlus::Action::ProxyValidate> and shows the response message.
+Shows the CAS 2.0 proxy ticket validation response.
=cut
on 'proxyValidate' => run {
- my $proxy_validate = Jifty->web->new_action(
- class => 'ProxyValidate',
- arguments => {
- service => get 'service',
- ticket => get 'ticket',
- pgtUrl => get 'pgtUrl',
- renew => get 'renew',
- },
- );
- $proxy_validate->run;
-
- set result => $proxy_validate->result;
+ my $result = Jifty->web->response->result('proxy_validate');
+ set result => $result;
show '/proxyValidate';
};
=head2 proxy
-Runs L<CASPlus::Action::Proxy> and returns the response message.
+Shows the CAS 2.0 proxy ticket request response.
=cut
on 'proxy' => run {
- my $proxy = Jifty->web->new_action(
- class => 'Proxy',
- arguments => {
- pgt => get 'pgt',
- targetService => get 'targetService',
- },
- );
- $proxy->run;
-
- set result => $proxy->result;
+ my $result = Jifty->web->response->result('proxy');
+ set result => $result;
show '/proxy';
};
More information about the Jifty-commit
mailing list