Parent Directory
|
Revision Log
initial import
1 #!/usr/bin/perl 2 3 ## change-email.pl 4 ## email update script for the WeBWorK project 5 6 #################################################################### 7 # Copyright @ 1995-1998 University of Rochester 8 # All Rights Reserved 9 #################################################################### 10 11 12 require 5.001; 13 use strict; 14 use lib '/ww/webwork/development/'; # mainWeBWorKDirectory; 15 16 use Global; 17 use Auth; 18 use CGI qw(:standard); 19 use Net::SMTP; 20 21 my $scriptDirectory = getWebworkScriptDirectory(); 22 23 my $User = param('user') || &error_form('No user', 'No user name specified.'); 24 my $Key = param('key') || &error_form('No key', 'No session key specified.'); 25 my $Course = param('course') || &error_form('No course', 'No course specified.'); 26 27 &Global::getCourseEnvironment($Course); 28 29 my $Passwd_file = &getCoursePasswordFile($Course); 30 &Global::error("", "Can't read $Passwd_file") unless (-r $Passwd_file); 31 32 my $Key_file = &getCourseKeyFile($Course); 33 &Global::error("", "Can't read $Key_file") unless (-r $Key_file); 34 35 ## make sure user's already been authenticated 36 &verify_key($User, $Key, $Key_file, $Course); 37 38 ## exit if practice user 39 if ($User =~ /^$Global::practiceUser/) { 40 wwerror('Operation not allowed', "practice users are not allowed to change email addresses.\nPlease go back and select: Begin Problem Set."); 41 } 42 43 require "${scriptDirectory}$Global::HTMLglue_pl"; 44 require "${scriptDirectory}$Global::classlist_DBglue_pl"; 45 require "${scriptDirectory}$Global::FILE_pl"; 46 47 48 my $databaseDirectory = $Global::databaseDirectory; 49 50 ## If this is the firstTime the script is called, print a blank form else 51 ## change the email address. This allows empty email addresses 52 53 my $firstTime = param('firstTime'); 54 my $newEmailAdd =''; 55 my $oldEmailAdd =''; 56 $newEmailAdd = param('newEmailAdd') if defined param('newEmailAdd'); 57 $oldEmailAdd = param('oldEmailAdd') if defined param('oldEmailAdd'); 58 59 #my $classlistFile = getCourseClasslistFile($Course); 60 $newEmailAdd =~ s/\s//g; ##remove spaces 61 wwerror('Illegal email address', 'Your email address has not been changed.') unless 62 ($newEmailAdd =~ /^[\w\.\@]*$/ ); 63 64 # if this is the first call print the form 65 if ($firstTime eq 'firstTime') { 66 &change_em_form; 67 } 68 69 # otherwise we should change the email address { 70 elsif ($firstTime eq 'cemadd') { 71 &change_em_add ($User,$oldEmailAdd ,$newEmailAdd); 72 success_form ($newEmailAdd); 73 } 74 75 else { 76 wwerror($0,'The script did not receive the proper input data.','',''); 77 } 78 79 ## end of main script 80 81 sub change_em_form { 82 my $course = shift; 83 $oldEmailAdd = &findEmailAdd($User); 84 param('firstTime','cemadd'); ##change hidden parameter 85 86 print &htmlTOP('Change Email Address Page', $Global::background_plain_url), 87 hr, 88 h1('Change Email Address Page'), 89 start_form('POST', url), 90 "Please enter (or edit) the email address for your ", b($Course), 91 " account, ", b($User), ".<BR>", 92 "Be careful. If you enter an incorrect email address, you may miss receiving important information.", 93 94 p, 95 textfield('newEmailAdd', "$oldEmailAdd", 40), " Email Address", br, 96 p, 97 submit('Set your new email address'), 98 hidden('user'), 99 hidden('key'), 100 hidden('course'), 101 hidden('firstTime'), 102 hidden('oldEmailAdd',"$oldEmailAdd"), 103 end_form, end_html; 104 } 105 106 107 sub success_form { 108 my ($newEmailAdd) = @_; 109 print &htmlTOP('Email Address Changed', $Global::background_okay_url), 110 hr, 111 h1('Email Address Changed'), 112 "Your new email address for ", b($Course), " has been changed to <BR> $newEmailAdd", 113 p, 114 "Email messages confirming this change will be sent both to your new and old email address 115 (if they are not blank). If you don't receive the confirming message at your new email address, 116 it means there may be a problem with the new address you entered.", 117 p, 118 start_form('POST', "${Global::cgiWebworkURL}login.pl"), 119 p,"\n", 120 hidden('course'), "\n", hidden('user'), "\n", hidden('key'), 121 submit('Continue'), 122 end_form, end_html; 123 } 124 125 126 sub findEmailAdd { 127 my ($User) = @_; 128 attachCLRecord($User); 129 my $email_address = CL_getStudentEmailAddress($User); 130 131 return $email_address; 132 } 133 134 sub change_em_add { 135 my ($User,$oldEmailAdd ,$newEmailAdd) = @_; 136 137 attachCLRecord($User); 138 my $lastName = CL_getStudentLastName($User); 139 my $firstName = CL_getStudentFirstName($User); 140 141 CL_putStudentEmailAddress($newEmailAdd,$User); 142 saveCLRecord($User); 143 144 ## send confirming email messages to the old and new addresses 145 if ($oldEmailAdd =~ /\S/) { 146 my $msg = emailMsg($oldEmailAdd, $lastName, $firstName, $newEmailAdd, $oldEmailAdd); 147 148 my $smtp = Net::SMTP->new($Global::smtpServer, Timeout=>20); 149 $smtp->mail($Global::webmaster); 150 if ($smtp->recipient($oldEmailAdd)) { 151 $smtp->data($msg); 152 } else {die "$oldEmailAdd";} 153 154 $smtp->quit; 155 156 # open (MAIL,"|$Global::SENDMAIL"); 157 # print MAIL "$msg"; 158 # close (MAIL); 159 } 160 if ($newEmailAdd =~ /\S/) { 161 my $msg = emailMsg($newEmailAdd, $lastName, $firstName, $newEmailAdd, $oldEmailAdd); 162 163 my $smtp = Net::SMTP->new($Global::smtpServer, Timeout=>20); 164 $smtp->mail($Global::webmaster); 165 $smtp->recipient($newEmailAdd); 166 $smtp->data($msg); 167 $smtp->quit; 168 169 170 # open (MAIL,"|$Global::SENDMAIL"); 171 # print MAIL "$msg"; 172 # close (MAIL); 173 } 174 } 175 176 sub emailMsg { 177 my ($emailAdd, $lastName, $firstName, $newEmailAdd, $oldEmailAdd) = @_; 178 my $msg =''; 179 my $fromAdd = $Global::feedbackAddress; 180 $fromAdd = $Global::feedbackAddress; 181 $msg = "To: $emailAdd 182 From: $fromAdd 183 Subject: Email address changed 184 185 Dear $firstName $lastName, 186 187 Your email address for $Course has been changed from: 188 $oldEmailAdd 189 to 190 $newEmailAdd 191 192 You should receive two email messages confirming this change. 193 One is being sent to your old email address and the other to your 194 new email address. 195 196 If either one of these email addresses is blank or invalid, 197 obviously you will not receive the message sent to that address.\n"; 198 199 $msg; 200 }
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |