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