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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 720 - (download) (as text) (annotate)
Fri Jan 31 20:38:44 2003 UTC (10 years, 4 months ago) by malsyned
File size: 3558 byte(s)
effectiveUser audit complete on all the content generators except
Hardcopy
-Dennis

    1 ################################################################################
    2 # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project
    3 # $Id$
    4 ################################################################################
    5 
    6 package WeBWorK::ContentGenerator::Options;
    7 
    8 =head1 NAME
    9 
   10 WeBWorK::ContentGenerator::Options - Change user options.
   11 
   12 =cut
   13 
   14 use strict;
   15 use warnings;
   16 use base qw(WeBWorK::ContentGenerator);
   17 use Apache::Constants qw(:common);
   18 use CGI qw();
   19 use WeBWorK::ContentGenerator;
   20 use WeBWorK::DB::WW;
   21 
   22 sub initialize {
   23   my $self = shift;
   24   my $r = $self->{r};
   25   my $ce = $self->{courseEnvironment};
   26 
   27   $self->{cldb} = WeBWorK::DB::Classlist->new($ce);
   28   $self->{authdb} = WeBWorK::DB::Auth->new($ce);
   29   $self->{effectiveUser} = $self->{cldb}->getUser($r->param('effectiveUser'));
   30 }
   31 
   32 sub path {
   33   my ($self, $args) = @_;
   34 
   35   my $ce = $self->{courseEnvironment};
   36   my $root = $ce->{webworkURLs}->{root};
   37   my $courseName = $ce->{courseName};
   38   return $self->pathMacro($args,
   39     "Home" => "$root",
   40     $courseName => "$root/$courseName",
   41     "User Options" => "",
   42   );
   43 }
   44 
   45 sub title {
   46   my $self = shift;
   47 
   48   return "User Options for " . $self->{effectiveUser}->first_name
   49     . " " . $self->{effectiveUser}->last_name;
   50 }
   51 
   52 sub body {
   53   my $self = shift;
   54   my $r = $self->{r};
   55   my $effectiveUser = $self->{effectiveUser};
   56 
   57   my $changeOptions = $r->param("changeOptions");
   58   my $newP = $r->param("newPassword");
   59   my $confirmP = $r->param("confirmPassword");
   60   my $newA = $r->param("newAddress");
   61   my $confirmA = $r->param("confirmAddress");
   62 
   63   print CGI::start_form(-method=>"POST", -action=>$r->uri);
   64   print $self->hidden_authen_fields;
   65   print CGI::h2("Change Password");
   66   if ($changeOptions) {
   67     if ($newP or $confirmP) {
   68       if ($newP eq $confirmP) {
   69         # possibly do some format checking?
   70         eval { $self->{authdb}->setPassword($effectiveUser->id, $newP) };
   71         if ($@) {
   72           print CGI::p("Couldn't change your
   73           password: $@");
   74         } else {
   75           print CGI::p("Your password has been
   76           changed.");
   77         }
   78       } else {
   79         print CGI::p("The passwords you entered in the
   80         New Password and Confirm Password fields don't
   81         match. Please retype your new password and try
   82         again.");
   83       }
   84     }
   85   }
   86   print CGI::table(
   87     CGI::Tr(
   88       CGI::td("New Password"),
   89       CGI::td(CGI::password_field("newPassword")),
   90     ),
   91     CGI::Tr(
   92       CGI::td("Confirm Password"),
   93       CGI::td(CGI::password_field("confirmPassword")),
   94     ),
   95   );
   96   print CGI::h2("Change Email Address");
   97   if ($changeOptions) {
   98     if ($newA or $confirmA) {
   99       if ($newA eq $confirmA) {
  100         # possibly do some format checking?
  101         my $oldA = $effectiveUser->email_address;
  102         $effectiveUser->email_address($newA);
  103         eval { $self->{cldb}->setUser($effectiveUser) };
  104         if ($@) {
  105           $effectiveUser->email_address($oldA);
  106           print CGI::p("Couldn't change your
  107           email address: $@");
  108         } else {
  109           print CGI::p("Your email address has
  110           been changed.");
  111           $newA = $confirmA = "";
  112         }
  113       } else {
  114         print CGI::p("The addresses you entered in the
  115         New Address and Confirm Address fields don't
  116         match. Please retype your new address and try
  117         again.");
  118       }
  119     }
  120   }
  121   print CGI::table(
  122     CGI::Tr(
  123       CGI::td("Current Address"),
  124       CGI::td($effectiveUser->email_address),
  125     ),
  126     CGI::Tr(
  127       CGI::td("New Address"),
  128       CGI::td(CGI::textfield("newAddress", $newA)),
  129     ),
  130     CGI::Tr(
  131       CGI::td("Confirm Address"),
  132       CGI::td(CGI::textfield("confirmAddress", $confirmA)),
  133     ),
  134   );
  135   print CGI::br();
  136   print CGI::submit("changeOptions", "Change User Options");
  137   print CGI::end_form();
  138 
  139   return "";
  140 }
  141 
  142 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9