chiark / gitweb /
Testing: autotest: Move some code about
[cgi-auth-flexible.git] / cgi-auth-flexible.pm
index e52441b802b1647dff1f927fd7018ee7aa959827..21805cffd8057a177222a6177d3dd3113d6a2bb6 100644 (file)
@@ -910,9 +910,17 @@ sub _check_divert_core ($) {
 
     die unless $cookt eq 'y';
     unless ($r->{S}{promise_check_mutate} && $meth eq 'GET') {
+        if ($parmt eq 't' || $parmt eq 'n') {
+            return ({ Kind => 'STALE',
+                      Message => $r->_gt("Login session interrupted."),
+                      _CookieRaw => $cooks,
+                      Params => { } });
+        }
         die unless $parmt eq 'y';
         die unless $cookh eq $parmh;
     }
+    $r->_db_update_last($cooku,$parmh);
+
     $r->{ParmT} = $parmt;
     $r->{AssocRaw} = $cooks;
     $r->{UserOK} = $cooku;
@@ -1018,6 +1026,16 @@ sub _db_record_login_ok ($$$) {
             $h, $user, time);
 }
 
+sub _db_update_last ($$) {
+    # revokes $h if it's valid; no-op if it's not
+    my ($r,$user,$h) = @_;
+    my $dbh = $r->{Dbh};
+    $dbh->do("UPDATE $r->{S}{db_prefix}_assocs".
+             " SET last = ?".
+            " WHERE username = ? AND assochash = ?", {},
+             time, $user, $h);
+}
+
 sub check_divert ($) {
     my ($r) = @_;
     if (exists $r->{Divert}) {
@@ -1121,6 +1139,10 @@ sub check_ok ($) {
        $title = $r->_gt('Not logged in');
        push @body, $divert->{Message};
        push @body, $r->_ch('gen_login_link', $params);
+    } elsif ($kind =~ m/^STALE/) {
+        $title = $r->_gt('Re-entering secure site.');
+        push @body, $divert->{Message};
+        push @body, $r->_ch('gen_postmainpage_form', $params);
     } elsif ($kind =~ m/^MAINPAGEONLY$/) {
         $title = $r->_gt('Entering secure site.');
         push @body, $divert->{Message};