[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Logout.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Logout.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3746 - (download) (as text) (annotate)
Mon Nov 7 21:29:27 2005 UTC (7 years, 6 months ago) by sh002i
File size: 3500 byte(s)
clear Authen.pm's verify cache upon logout, don't overload if_loggedin()
or links() anymore.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Logout.pm,v 1.10 2005/07/14 13:15:25 glarose Exp $
    5 #
    6 # This program is free software; you can redistribute it and/or modify it under
    7 # the terms of either: (a) the GNU General Public License as published by the
    8 # Free Software Foundation; either version 2, or (at your option) any later
    9 # version, or (b) the "Artistic License" which comes with this package.
   10 #
   11 # This program is distributed in the hope that it will be useful, but WITHOUT
   12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 package WeBWorK::ContentGenerator::Logout;
   18 use base qw(WeBWorK::ContentGenerator);
   19 
   20 =head1 NAME
   21 
   22 WeBWorK::ContentGenerator::Logout - invalidate key and display logout message.
   23 
   24 =cut
   25 
   26 use strict;
   27 use warnings;
   28 use CGI qw();
   29 
   30 sub pre_header_initialize {
   31   my ($self) = @_;
   32   my $r = $self->r;
   33   my $ce = $r->ce;
   34   my $authen = $r->authen;
   35 
   36   # get rid of stored authentication info (this is kind of a hack. i have a better way
   37   # in mind but it requires pretty much rewriting Authen/Login/Logout. :-( )
   38   $authen->forget_verification;
   39 
   40   my $cookie = Apache::Cookie->new($r,
   41     -name => "WeBWorKAuthentication",
   42     -value => "",
   43     -expires => "-1D",
   44     -domain => $r->hostname,
   45     -path => $ce->{webworkURLRoot},
   46     -secure => 0,
   47   );
   48   $r->headers_out->set("Set-Cookie" => $cookie->as_string);
   49 }
   50 
   51 ## This content generator is NOT logged in.
   52 #sub if_loggedin {
   53 # my ($self, $arg) = @_;
   54 #
   55 # return !$arg;
   56 #}
   57 #
   58 ## suppress links
   59 #sub links {
   60 # return "";
   61 #}
   62 
   63 sub body {
   64   my ($self) = @_;
   65   my $r = $self->r;
   66   my $ce = $r->ce;
   67   my $db = $r->db;
   68   my $urlpath = $r->urlpath;
   69 
   70   my $courseID = $urlpath->arg("courseID");
   71   my $userID = $r->param("user");
   72 
   73   eval { $db->deleteKey($userID) };
   74   if ($@) {
   75     print CGI::div({class=>"ResultsWithError"},
   76       CGI::p("Something went wrong while logging out of WeBWorK: $@")
   77     );
   78   }
   79 
   80 # also check to see if there is a proctor key associated with this login.  if
   81 #    there is a proctor user, then we must have a proctored test, so we try
   82 #    and delete the key
   83   my $proctorID = defined($r->param("proctor_user")) ?
   84       $r->param("proctor_user") : '';
   85   if ( $proctorID ) {
   86       eval { $db->deleteKey( "$userID,$proctorID" ); };
   87       if ( $@ ) {
   88     print CGI::div({ class=> "ResultsWithError" },
   89              CGI::p("Error when clearing proctor key: $@"));
   90       }
   91 # we may also have a proctor key from grading the test
   92       eval { $db->deleteKey( "$userID,$proctorID,g" ); };
   93       if ( $@ ) {
   94     print CGI::div({ class=> "ResultsWithError" },
   95              CGI::p("Error when clearing proctor grading " .
   96               "key: $@"));
   97       }
   98   }
   99 
  100   my $problemSets = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", courseID => $courseID);
  101   my $loginURL = $r->location . $problemSets->path;
  102 
  103   print CGI::p("You have been logged out of WeBWorK.");
  104 
  105   print CGI::start_form(-method=>"POST", -action=>$loginURL);
  106   print CGI::hidden("user", $userID);
  107   print CGI::hidden("force_passwd_authen", 1);
  108   print CGI::p({align=>"center"}, CGI::submit("submit", "Log In Again"));
  109   print CGI::end_form();
  110 
  111   return "";
  112 }
  113 
  114 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9