[Jifty-commit] r3693 - in apps/CASPlus/trunk: lib/CASPlus share/web/templates

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Jul 14 20:35:39 EDT 2007


Author: sterling
Date: Sat Jul 14 20:35:29 2007
New Revision: 3693

Added:
   apps/CASPlus/trunk/lib/CASPlus/View.pm
Removed:
   apps/CASPlus/trunk/share/web/templates/login
   apps/CASPlus/trunk/share/web/templates/logout
   apps/CASPlus/trunk/share/web/templates/proxy
   apps/CASPlus/trunk/share/web/templates/proxyValidate
   apps/CASPlus/trunk/share/web/templates/serviceValidate
   apps/CASPlus/trunk/share/web/templates/status
   apps/CASPlus/trunk/share/web/templates/validate
Modified:
   apps/CASPlus/trunk/   (props changed)

Log:
 r8082 at dynpc145:  andrew | 2007-07-14 19:35:06 -0500
 Moving templates from Mason to Template::Declare.


Added: apps/CASPlus/trunk/lib/CASPlus/View.pm
==============================================================================
--- (empty file)
+++ apps/CASPlus/trunk/lib/CASPlus/View.pm	Sat Jul 14 20:35:29 2007
@@ -0,0 +1,275 @@
+use strict;
+use warnings;
+
+package CASPlus::View;
+use Jifty::View::Declare -base;
+
+our ($xml, $casns);
+
+sub cas_xml(&) {
+    my $code = shift;
+
+    sub {
+        my $output = '';
+
+        local $casns = 'http://www.yale.edu/tp/cas';
+        local $xml   = XML::Writer->new( 
+            OUTPUT      => \$output, 
+            DATA_MODE   => 1,
+            DATA_INDENT => 2,
+            NAMESPACES  => 1,
+            PREFIX_MAP  => {
+                $casns => 'cas',
+            },
+        );
+
+        Jifty->handler->apache->content_type('application/xml; charset=utf-8');
+
+        $xml->xmlDecl("UTF-8");
+        
+        $xml->startTag([ $casns, 'serviceResponse' ]);
+
+        $code->();
+
+        $xml->endTag;
+        $xml->end;
+
+        outs_raw($output);
+    };
+}
+
+template login => page {
+    { title is 'Login' };
+
+    my $service = get('service') || undef;
+    my $lt      = get 'lt';
+
+    form {
+        attr { method => 'POST', action => '/login' };
+
+        if ($service) {
+            outs(Jifty::Web::Form::Field->new(
+                render_as     => 'Hidden',
+                name          => 'service',
+                input_name    => 'service',
+                default_value => $service,
+            )->render);
+        }
+
+        outs(Jifty::Web::Form::Field->new(
+            render_as  => 'Text',
+            name       => 'username',
+            input_name => 'username',
+            label      => _('Username'),
+        )->render);
+
+        outs(Jifty::Web::Form::Field->new(
+            render_as  => 'Password',
+            name       => 'password',
+            input_name => 'password',
+            label      => _('Password'),
+        )->render);
+
+        if (Jifty->config->app('Login')->{'ShowLoginWarningCheckbox'}) {
+            outs(Jifty::Web::Form::Field->new(
+                render_as  => 'Checkbox',
+                name       => 'warn',
+                input_name => 'warn',
+                label      => _('Warn me when other services log me in.'),
+                hints      => _('You are a logging in to a service which may be used by multiple web sites. By checking this box you are asking to see a special message letting you know whenever another web site asks who you are.'),
+            )->render);
+        }
+
+        outs(Jifty::Web::Form::Field->new(
+            render_as     => 'Hidden',
+            name          => 'lt',
+            input_name    => 'lt',
+            default_value => $lt->login_ticket,
+        )->render);
+        
+        form_submit(label => 'Login');
+    };
+};
+
+template 'logout' => page {
+    { title is 'Logged out' };
+
+    if (Jifty->web->current_user->id) {
+        p { 
+            outs(_('Oddly enough, you are still logged in as '));
+            span { Jifty->web->current_user->user_object->username };
+        };
+    }
+
+    else {
+        p { _('You are now logged out.') };
+    }
+};
+
+template 'status' => page {
+    { title is 'Login Status' };
+
+    if (Jifty->web->current_user->id) {
+        p { 
+            outs(_('You are currently signed in as '));
+            hyperlink( 
+                label => Jifty->web->current_user->user_object->username,
+                url   => '/user/me',
+            );
+        };
+
+        p { hyperlink( label => 'Logout', url => '/logout' ); };
+    }
+
+    else {
+        p { _('You are not currently signed in.'); };
+
+        p { hyperlink( label => 'Login', url => '/login' ); };
+    }
+};
+
+template 'proxy' => cas_xml {
+    my $result = get 'result';
+
+    if ($result->success) {
+        $xml->startTag([ $casns, 'proxySuccess' ]);
+        $xml->dataElement(
+            [ $casns, 'proxyTicket' ], $result->content('ticket')
+        );
+        $xml->endTag;
+    }
+
+    else {
+        $xml->dataElement(
+            [ $casns, 'proxyFailure' ], 
+            $result->error,
+            code => $result->content('code')
+        );
+    }
+};
+
+template 'proxyValidate' => cas_xml {
+    my $result = get 'result';
+
+    if ($result->success) {
+        $xml->startTag([ $casns, 'authenticationSuccess' ]);
+        $xml->dataElement([ $casns, 'user' ], $result->content('username'));
+
+        if ($result->content('proxy_granting_ticket')) {
+            $xml->dataElement(
+                [ $casns, 'proxyGrantingTicket' ],
+                $result->content('proxy_granting_ticket'),
+            );
+        }
+
+        if ($result->content('proxies')) {
+            $xml->startTag([ $casns, 'proxies' ]);
+            for my $proxy (@{ $result->content('proxies') }) {
+                $xml->dataElement([ $casns, 'proxy' ], $proxy);
+            }
+            $xml->endTag;
+        }
+
+        $xml->endTag;
+    }
+
+    else {
+        $xml->dataElement(
+            [ $casns, 'authenticationFailure' ],
+            $result->error,
+            code => $result->content('code'),
+        );
+    }
+};
+
+template 'serviceValidate' => cas_xml {
+    my $result = get 'result';
+
+    if ($result->success) {
+        $xml->startTag([ $casns, 'authenticationSuccess' ]);
+        $xml->dataElement([ $casns, 'user' ], $result->content('username'));
+
+        if ($result->content('proxy_granting_ticket')) {
+            $xml->dataElement([ $casns, 'proxyGrantingTicket' ],
+                $result->content('proxy_granting_ticket')
+            );
+        }
+
+        $xml->endTag;
+    }
+
+    else {
+        $xml->dataElement(
+            [ $casns, 'authenticationFailure' ],
+            $result->error,
+            code => $result->content('code'),
+        );
+    }
+};
+
+template 'validate' => sub {
+    Jifty->handler->apache->content_type('text/plain');
+
+    my $result = get 'result';
+
+    outs( $result->success ? "yes\n" : "no\n" );
+
+    if ($result->success) {
+        outs( $result->content('username') . "\n" );
+    }
+};
+
+#use Template::Declare::XML;
+#use Jifty::View::Declare schema {
+#    namespace cas => 'http://www.yale.edu/tp/cas';
+#    default_prefix is 'cas';
+#
+#    tag serviceResponse =>
+#        is not_empty;
+#
+#    tag authenticationSuccess =>
+#        is not_empty;
+#
+#    tag user =>
+#        is data;
+#
+#    tag proxyGrantingTicket =>
+#        is data;
+#
+#    tag authenticationFailure =>
+#        attributes {
+#            attribute code =>
+#                is required;
+#        },
+#        is not_empty;
+#};
+#
+#template 'serviceValidate' => sub {
+#    my $result = get 'result';
+#
+#    xml_decl { version => 1.0, encoding => 'UTF-8' };
+#
+#    serviceResponse {
+#        if ($result->success) {
+#            authenticationSuccess {
+#                user { $result->content('username'); };
+#
+#                if ($result->content('proxy_granting_ticket')) {
+#                    proxyGrantingTicket {
+#                        $result->content('proxy_granting_ticket');
+#                    };
+#                }
+#            };
+#        }
+#
+#        else {
+#            authenticationFailure {
+#                attr { code => $result->content('code') };
+#                
+#                $result->error;
+#            };
+#        }
+#    };
+#};
+
+1;


More information about the Jifty-commit mailing list