Parent Directory
|
Revision Log
This commit was manufactured by cvs2svn to create branch 'rel-2-3-dev'.
1 ################################################################################ 2 # WeBWorK Online Homework Delivery System 3 # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ 4 # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Options.pm,v 1.23 2006/07/16 02:40:34 gage 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::Options; 18 use base qw(WeBWorK::ContentGenerator); 19 20 =head1 NAME 21 22 WeBWorK::ContentGenerator::Options - Change user options. 23 24 =cut 25 26 use strict; 27 use warnings; 28 #use CGI qw(-nosticky ); 29 use WeBWorK::CGI; 30 use WeBWorK::Utils qw(cryptPassword dequote); 31 32 sub body { 33 my ($self) = @_; 34 my $r = $self->r; 35 my $db = $r->db; 36 my $authz = $r->authz; 37 38 my $userID = $r->param("user"); 39 my $User = $db->getUser($userID); 40 die "record not found for user '$userID'." unless defined $User; 41 42 my $eUserID = $r->param('effectiveUser'); 43 my $EUser = $db->getUser($eUserID); # checked 44 die "record not found for effective user '$eUserID'." unless defined $EUser; 45 46 my $user_name = $User->first_name . " " . $User->last_name; 47 my $e_user_name = $EUser->first_name . " " . $EUser->last_name; 48 49 my $changeOptions = $r->param("changeOptions"); 50 my $currP = $r->param("currPassword"); 51 my $newP = $r->param("newPassword"); 52 my $confirmP = $r->param("confirmPassword"); 53 my $newA = $r->param("newAddress"); 54 55 print CGI::start_form(-method=>"POST", -action=>$r->uri); 56 print $self->hidden_authen_fields; 57 58 print CGI::h2("Change Password"); 59 60 if ($changeOptions and ($currP or $newP or $confirmP)) { 61 62 if ($authz->hasPermissions($userID, "change_password")) { 63 64 my $Password = eval {$db->getPassword($User->user_id)}; # checked 65 warn "Can't get password record for user '$userID': $@" if $@ or not defined $Password; 66 67 my $EPassword = eval {$db->getPassword($EUser->user_id)}; # checked 68 warn "Can't get password record for effective user '$eUserID': $@" if $@ or not defined $EPassword; 69 70 if (crypt($currP, $Password->password) eq $Password->password) { 71 if ($newP or $confirmP) { 72 if ($newP eq $confirmP) { 73 $EPassword->password(cryptPassword($newP)); 74 eval { $db->putPassword($EPassword) }; 75 if ($@) { 76 print CGI::div({class=>"ResultsWithError"}, 77 CGI::p("Couldn't change $e_user_name\'s password: $@"), 78 ); 79 } else { 80 print CGI::div({class=>"ResultsWithoutError"}, 81 CGI::p("$e_user_name\'s password has been changed."), 82 ); 83 } 84 } else { 85 print CGI::div({class=>"ResultsWithError"}, 86 CGI::p( 87 "The passwords you entered in the ", 88 CGI::b("$e_user_name\'s New Password"), " and ", 89 CGI::b("Confirm $e_user_name\'s New Password"), " fields 90 don't match. Please retype your new password and try 91 again." 92 ), 93 ); 94 } 95 } else { 96 print CGI::div({class=>"ResultsWithError"}, 97 CGI::p("$e_user_name\'s new password cannot be blank."), 98 ); 99 } 100 } else { 101 print CGI::div({class=>"ResultsWithError"}, 102 CGI::p( 103 "The password you entered in the ", CGI::b("$user_name\'s 104 Current Password"), " field does not match your current 105 password. Please retype your current password and try 106 again." 107 ), 108 ); 109 } 110 111 } else { 112 print CGI::div({class=>"ResultsWithError"}, 113 CGI::p("You do not have permission to change your password.")) 114 unless $changeOptions and ($currP or $newP or $confirmP); # avoid double message 115 } 116 117 } 118 119 if ($authz->hasPermissions($userID, "change_password")) { 120 print CGI::table({class=>"FormLayout"}, 121 CGI::Tr({}, 122 CGI::td("$user_name\'s Current Password"), 123 CGI::td(CGI::password_field(-name=>"currPassword")), 124 ), 125 CGI::Tr({}, 126 CGI::td("$e_user_name\'s New Password"), 127 CGI::td(CGI::password_field(-name=>"newPassword")), 128 ), 129 CGI::Tr({}, 130 CGI::td("Confirm $e_user_name\'s New Password"), 131 CGI::td(CGI::password_field(-name=>"confirmPassword")), 132 ), 133 ); 134 } else { 135 print CGI::p("You do not have permission to change your password."); 136 } 137 138 print CGI::h2("Change Email Address"); 139 140 if ($changeOptions and $newA) { 141 if ($authz->hasPermissions($userID, "change_email_address")) { 142 143 my $oldA = $EUser->email_address; 144 $EUser->email_address($newA); 145 eval { $db->putUser($EUser) }; 146 if ($@) { 147 $EUser->email_address($oldA); 148 print CGI::div({class=>"ResultsWithError"}, 149 CGI::p("Couldn't change your email address: $@"), 150 ); 151 } else { 152 print CGI::div({class=>"ResultsWithoutError"}, 153 CGI::p("Your email address has been changed."), 154 ); 155 } 156 157 } else { 158 print CGI::div({class=>"ResultsWithError"}, 159 CGI::p("You do not have permission to change email addresses."), 160 ); 161 } 162 } 163 164 if ($authz->hasPermissions($userID, "change_email_address")) { 165 print CGI::table({class=>"FormLayout"}, 166 CGI::Tr({}, 167 CGI::td("$e_user_name\'s Current Address"), 168 CGI::td($EUser->email_address), 169 ), 170 CGI::Tr({}, 171 CGI::td("$e_user_name\'s New Address"), 172 CGI::td(CGI::textfield(-name=>"newAddress", -text=>$newA)), 173 ), 174 ); 175 } else { 176 print CGI::p("You do not have permission to change email addresses.") 177 unless $changeOptions and $newA; # avoid double message 178 } 179 180 print CGI::br(); 181 print CGI::submit("changeOptions", "Change User Options"); 182 print CGI::end_form(); 183 184 return ""; 185 } 186 187 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |