[Yapcom checkin] rev 25 - / lib/YAPC t t/lib/YAPC/Test templates

[prev] [thread] [next] [lurker] [Date index for 2003/11/24]

From: svn
Subject: [Yapcom checkin] rev 25 - / lib/YAPC t t/lib/YAPC/Test templates
Date: 19:11 on 24 Nov 2003
Author: gabor
Date: 2003-11-24 19:11:48 +0200 (Mon, 24 Nov 2003)
New Revision: 25

Modified:
   README
   lib/YAPC/Organizer.pm
   t/03-web-adduser.t
   t/lib/YAPC/Test/Data.pm
   templates/login.tmpl
Log:
moving the code that checks if user was logged in
to the cgiapp_prerun method
nearly everything works through this one

Modified: README
===================================================================
--- README	2003-11-24 16:06:33 UTC (rev 24)
+++ README	2003-11-24 17:11:48 UTC (rev 25)
@@ -36,7 +36,7 @@
 ---------
 0.07_03 2003.11.
     - refactoring: using Class::DBI more in the way it should be used
-    - refactoring: moving over run_mode dispatching 
+    - refactoring: moving run_mode dispatching, cleaning up the run_modes and authentication 
 
 
 0.07_02 2003.11.24

Modified: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	2003-11-24 16:06:33 UTC (rev 24)
+++ lib/YAPC/Organizer.pm	2003-11-24 17:11:48 UTC (rev 25)
@@ -19,6 +19,8 @@
 use base 'CGI::Application';
 use Data::Dumper;  # for playing with debugging
 
+my @user_pages = qw(proposal user_account personal_info change_password);  # list pages that require valid login to access
+my @admin_pages = qw(admin admin_list_people admin_list_proposals); # list of pages accessible to administrators only
 
 
 
@@ -47,7 +49,6 @@
 
    #warn "PRE: $self\n";
    #warn "PRE: @_\n";
-   #$self->prerun_mode('login');
 
    # REQUEST_URI looks like this:  /content.html
    my $page = $ENV{REQUEST_URI} || '';
@@ -57,6 +58,16 @@
 
    if ($page eq 'list_people') { $self->prerun_mode('list_people') }
 
+   if (grep {$_ eq $page} @user_pages) {
+       if (not $self->is_logged_in) {
+          $self->param('yapcom_next_page' => "$page.html");
+          $self->prerun_mode('login');
+          return;
+       }
+   }       
+
+   #if (grep {$_ eq $page} (@user_pages, @admin_pages)) {
+
    my $filename = "$templates_dir/$page.tmpl";
 
    if (not -e $filename) {
@@ -65,16 +76,6 @@
    }
 }
 
-
-sub is_logged_in {
-    my $self = shift; 
-    my $q = $self->query;
-
-    # retreive the Cookie and check if this represents a valid user
-    my $cookie = $q->cookie('Yapcom');
-    YAPC::Login->get_user_id(cookie => $cookie);
-}
-
 sub default {
     my $self = shift; 
     my $q = $self->query;
@@ -103,8 +104,6 @@
         my $t = $self->_server_page('user_account', "$templates_dir/user_account.tmpl");
         return $t->output;
     }
-    my @user_pages = qw(proposal user_account personal_info change_password);  # list pages that require valid login to access
-    my @admin_pages = qw(admin admin_list_people admin_list_proposals); # list of pages accessible to administrators only
 
     if (not $id and 
         not $self->header_props() and   # set within this run in do_login
@@ -145,6 +144,16 @@
     return $t->output;
 }
 
+sub is_logged_in {
+    my $self = shift; 
+    my $q = $self->query;
+
+    # retreive the Cookie and check if this represents a valid user
+    my $cookie = $q->cookie('Yapcom');
+    YAPC::Login->get_user_id(cookie => $cookie);
+}
+
+
 sub do_no_such_page {
    my $self = shift;
        #$filename = "$templates_dir/error.tmpl";
@@ -362,19 +371,29 @@
     my $q = $self->query;
 
 
+    my $t = $self->_server_page('login', "$templates_dir/login.tmpl");
     my $login;
-    eval {
-       $login = YAPC::Login->new($q->Vars);
-    };
-    if ($@) {
-       my $msg = $@;
-       my $t = $self->_server_page('login', "$templates_dir/login.tmpl");
-       $t->param(MESSAGE => 'Login failed.');
+    #warn "Submit: " . join (':',$q->param()) . "\n";
+
+    if ($q->param('submit')) {
+       eval {
+         $login = YAPC::Login->new($q->Vars);
+       };
+       if ($@) {
+         my $msg = $@;
+         $t->param(MESSAGE => 'Login failed.');
+         return $t->output;
+       }
+    } else {
+       $t->param('next' => $self->param('yapcom_next_page')) if $self->param('yapcom_next_page');
        return $t->output;
-    } else {
-       my $path = $ENV{REQUEST_URI};
-       $path =~ s@[^/]*$@@; # remove everything after last /
-       my $cookie = $q->cookie(
+    }
+
+
+    # success
+    my $path = $ENV{REQUEST_URI};
+    $path =~ s@[^/]*$@@; # remove everything after last /
+    my $cookie = $q->cookie(
                         -name    =>'Yapcom',
                         -value   => $login->cookie,
                         -expires =>'+1d',
@@ -390,7 +409,6 @@
           $ENV{REQUEST_URI} = '/user_account.html';
        }
        $self->default;
-    }
 }
 
 

Modified: t/03-web-adduser.t
===================================================================
--- t/03-web-adduser.t	2003-11-24 16:06:33 UTC (rev 24)
+++ t/03-web-adduser.t	2003-11-24 17:11:48 UTC (rev 25)
@@ -202,6 +202,7 @@
    $user{run} = 'login';
    $user{email} = $user1{email};
    $user{password} = $user1{password};
+   $user{submit} = 1;
 
    my $q = CGI->new(\%user);
    my $webapp = YAPC::Organizer->new;
@@ -232,6 +233,7 @@
    $user{run} = 'login';
    $user{email} = $user1{email};
    $user{password} = $user1{password};
+   $user{submit} = 1;
 
    my $q = CGI->new(\%user);
    my $webapp = YAPC::Organizer->new;
@@ -260,6 +262,7 @@
    $user{run} = 'login';
    $user{email} = $user1{email};
    $user{password} = "$user1{password}xxx";
+   $user{submit} = 1;
 
    my $q = CGI->new(\%user);
    my $webapp = YAPC::Organizer->new;

Modified: t/lib/YAPC/Test/Data.pm
===================================================================
--- t/lib/YAPC/Test/Data.pm	2003-11-24 16:06:33 UTC (rev 24)
+++ t/lib/YAPC/Test/Data.pm	2003-11-24 17:11:48 UTC (rev 25)
@@ -114,6 +114,7 @@
    $user{run} = 'login';
    $user{email} = $people[$i]{email};
    $user{password} = $people[$i]{password};
+   $user{submit}  = 1;
 
    my $q = CGI->new(\%user);
    my $webapp = YAPC::Organizer->new;

Modified: templates/login.tmpl
===================================================================
--- templates/login.tmpl	2003-11-24 16:06:33 UTC (rev 24)
+++ templates/login.tmpl	2003-11-24 17:11:48 UTC (rev 25)
@@ -10,7 +10,7 @@
 <table>
 <tr><td>Email:</td><td><input  size=40 name="email" value="<TMPL_VAR NAME=email>" /></td></tr>
 <tr><td>Password:</td><td><input  size=40 name="password" type="password" /></td></tr>
-<tr><td></td><td><input type="submit" value="Login"></td></tr>
+<tr><td></td><td><input type="submit" name="submit" value="Login"></td></tr>
 </table>
 Not yet registered ? <a href=registration.html>Register here</a><br>
 Already registered but <a href=lost_validation.html>lost validation code ?</a><br>

Generated at 20:06 on 24 Nov 2003 by mariachi 0.51