-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendUserPassword.cgi
More file actions
executable file
·91 lines (74 loc) · 2.61 KB
/
sendUserPassword.cgi
File metadata and controls
executable file
·91 lines (74 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl -w
use CGI qw/:all/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use DataManipulation;
$user_zid = param("user_zid") || '';
$user_email = param("user_email") || '';
$send_password_flag=0;
$user_password='';
if(defined $user_zid && $user_zid ne '' && defined $user_email && $user_email ne ''){
open F,'<',"$users_dir/$user_zid/user.txt" or print header(-charset => "utf-8"),start_html(-title => "$user_zid asking send password to his/her email"),
"$user_zid not exist",
start_form(-action=>"sendUserPassword.cgi"),
"user_zid:",textfield(-name=>"user_zid"),
"<br/>",
"you register email",textfield(-name=>"user_email"),
submit,
end_form,
end_html;
while(my $line = <F>){
if($line =~ /email/i){
#$line =~ s/email\s*=\s*//i;
chomp $line;
if($line =~ /\Q$user_email\E/){
$send_password_flag=1;
}
}
if($line =~ /password/){
$user_password=$line;
#$user_password =~ s/\s*password\s*=\s*//;
}
}
close F;
if($send_password_flag == 1 && $user_password ne ''){
###grab it from https://www.tutorialspoint.com/perl/perl_sending_email.htm
my $to = $user_email;
my $from = 'z5089812@ad.unsw.edu.au';
my $subject = 'Password recovery';
#????? do not use an absolut url, how can you verify the email address
my $message = "user_zid:$user_zid, user_password:$user_password\n";
open(MAIL, "|/usr/sbin/sendmail -t");
# Email Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n";
# Email Body
print MAIL $message;
close(MAIL);
#sendEmail(getEmailByZid($user_zid),'z5089812@ad.unsw.edu.au','Password recovery',"user_zid:$user_zid, user_password:$user_password\n");
print redirect("welcomeLoginPage.cgi");
}else{
print header(-charset => "utf-8"),start_html(-title => "$user_zid asking send password to his/her email");
print "<p style=color:\"red\">email do not match, you should use the email when you registered</p>";
#print "$user_password 123";
print start_form(-action=>"sendUserPassword.cgi");
print "user_zid:",textfield(-name=>"user_zid");
print "<br/>";
print "you register email:",textfield(-name=>"user_email");
print "<br/>";
print submit;
print end_form;
print end_html;
}
}else{
print header(-charset => "utf-8"),start_html(-title => "$user_zid asking send password to his/her email");
print start_form(-action=>"sendUserPassword.cgi");
print "user_zid:",textfield(-name=>"user_zid"),"\n";
print "<br/>";
print "you register email:",textfield(-name=>"user_email");
print "<br/>";
print submit;
print end_form;
print end_html;
}