Subversion Repositories PEEPS

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/usr/bin/perl
2
 
3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
#my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
#close STDERR;
6
#open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
7
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
8
 
9
use strict;
10
use PEEPS;
11
use CGI qw/param header start_html url/;
12
use CGI::Cookie;
13
use Email::Valid;
14
 
15
#my $cookie_string = authenticate(1) || die;
16
#my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
17
my $query = new CGI;
18
my ($FORM, $userref, $buttonValue, $PEEPSid);
19
my ($USRMSG, $USRMSGERR, $RO, $PEEPSid_input, $recovery_options) = ("", "", "", "", "");
20
 
21
#if ($ENV{'QUERY_STRING'}) {
22
if ($ENV{'REQUEST_METHOD'} eq "POST") {
23
	$FORM->{account} = $query->param('account');
24
	$FORM->{action} = $query->param('action');
25
 
26
	if ($FORM->{action} eq "Cancel") {
27
		$FORM->{account} = "";
28
		$FORM->{action} = "";
29
		$buttonValue = "Search";
30
	} elsif ($FORM->{action} eq "Search") {
31
#	  if (! Email::Valid->address (-address => $FORM->{account}, -mxcheck => 1, -tldcheck => 1)) {
32
#	    $USRMSGERR = "Mal-formatted (or fake) Email Address!";
33
#	    $FORM->{account} = "";
34
#	    $buttonValue = "Search";
35
#	  } elsif ($userref = getUser($FORM->{account})) {
36
	  if ($userref = getUser($FORM->{account})) {
37
			$RO = "readonly";
38
			$PEEPSid_input = "<input type=hidden name=PEEPSid value=$userref->{id}>";
39
			$USRMSG = "Account found";
40
			if ((Email::Valid->address (-address => $FORM->{account}, -mxcheck => 1, -tldcheck => 1) and $FORM->{account} ne $userref->{username}) or $FORM->{account} =~ /^\d+$/) {
41
			  if ($userref->{username}) {
42
			  	## account has been set up
43
  			  my $mask = ($userref->{username} =~ s/(..).+(..)/$1 . '*' x (length($&)-4) . $2/e);
44
  			  $USRMSG .= " with Username: $userref->{username}<br>We can either email your username or reset your password...";
45
  			  $recovery_options = "	<TR>
46
                                  <TD valign=top>How can we help?</td>
47
  		                            <TD><input type=radio name=help value=username onclick=\"changeButtonLabel('Email')\"> Email Username<br>
48
  		                                <input type=radio name=help value=password onclick=\"changeButtonLabel('Reset')\"> Reset Password</TD>
49
  	                            </TR>";
50
          $buttonValue = "&lt;select&gt;";
51
  	    } elsif ($FORM->{account} =~ /^\d+$/) {
52
  	    	## account hasn't been set up, and we found it from member id
53
  			  my $mask = $userref->{email};
54
  			  $mask =~ s/(..).+(..@)/$1 . '*' x (length($&)-5) . $2/e;
55
  	    	$USRMSG .= " with email: $mask, but no Username has been set yet.<br>We can email a temporary password and set your Username to your email address...";
56
				  $buttonValue = "Setup";
57
  	    } else {
58
  	    	## account hasn't been set up, but they used email address
59
  	    	$USRMSG .= ", but no Username has been set yet.<br>We can email a temporary password and set your Username to your email address...";
60
				  $buttonValue = "Setup";
61
  	    }
62
			} else {
63
			  $USRMSG = "Username found.  Click Reset to reset your password, or Cancel to go back";
64
			  $buttonValue = "Reset";
65
			}
66
 
67
		} else {
68
			$USRMSGERR = "No user account found.";
69
			$buttonValue = "Search";
70
		}
71
	} elsif ($FORM->{action} eq "Email") {
72
	  sendUsername ($FORM->{account});
73
		logit($userref->{id}, "Username Emailed");
74
		exit;
75
	} elsif ($FORM->{action} eq "Reset" or $FORM->{action} eq "Setup") {
76
		if ($userref = getUser($FORM->{account})) {
77
			if ($userref->{id} eq $query->param('PEEPSid')) {
78
#        $userref->{username} = setUsername ($userref) unless $userref->{username};
79
    		resetPass ($userref);
80
				exit;
81
			} else {
82
				$USRMSGERR = "There appear to be shenanigans afoot. Please don't.";
83
				$buttonValue = "Search";
84
			}
85
		} else {
86
			$USRMSGERR = "There appears to be tomfoolery afoot. Please don't.";
87
			$buttonValue = "Search";
88
		}
89
	}
90
 
91
} else {
92
	$FORM->{account} = "";
93
	$FORM->{action} = "";
94
	$buttonValue = "Search";
95
}
96
 
97
 
98
print CGI::header();
99
 
100
#foreach (sort keys %ENV) {
101
#	print "$_: $ENV{$_}\n<br>";
102
#}
103
 
104
printRCHeader("Password Reset");
105
my $pageURL = url;
106
$USRMSGERR .= "<TR><TD colspan=2>&nbsp</TD></TR>" if $USRMSGERR;
107
$USRMSG    .= "<TR><TD colspan=2>&nbsp</TD></TR>" if $USRMSG;
108
 
109
print<<page1;
110
 
111
<p class="hint">Find your account by searching for your username, email address, or member id.<br>
112
 
113
 <FORM method=POST action=$pageURL> $PEEPSid_input
114
 <table>
115
	<TR><TD colspan=2>&nbsp</TD></TR>
116
	<TR><TD colspan=2 align=center>$USRMSG <FONT color=red><b>$USRMSGERR</b></font></TD></TR>
117
	<TR>
118
		<TD valign=top align=right><b>Lookup: </b></td>
119
		<TD valign=top><input type=text name=account value=$FORM->{account} $RO></TD>
120
	</TR>
121
	$recovery_options
122
	<TR><TD colspan=2>&nbsp</TD></TR>
123
	<TR><TD colspan=2 align=center><input type=submit id=subbutton name=action value=$buttonValue onclick="if (this.value === '&lt;select&gt;') { return false; }"><input type=button name=action value=Cancel onClick="location.href='/'"></TD></TR>
124
 </table></FORM>
125
</TABLE>
126
 
127
<script>
128
  function changeButtonLabel(newlabel) {
129
    const myButton = document.getElementById('subbutton');
130
    myButton.value = newlabel;
131
  }
132
</script>
133
 
134
page1
135
 
136
sub updateDBPass {
137
	my ($acctref, $STR) = @_;
138
	use DBI;
139
	use WebDB;
140
 
141
	my $dbh = WebDB::connect;
142
 
143
	my ($test, $PEEPSID) = $dbh->selectrow_array("select count(*), id from person where email = ? group by email", undef, $acctref->{email});
144
	return "ERROR: Email address [$acctref->{email}] not found." unless $test;
145
	return "ERROR: Too many accounts found [$acctref->{email}]." unless $test == 1;
146
 
147
	my $sth = $dbh->prepare("update authentication set password = password(?) where person_id=?");
148
	$sth->execute($STR, $PEEPSID);
149
 
150
  logit($PEEPSID, "Automated Password Reset");
151
	return;
152
}
153
 
154
sub resetPass {
155
	my $accountref = shift;
156
	my $pageURL = url;
157
	$pageURL =~ s|/[^/]+$|/|;
158
	$pageURL .= "view_user";
159
 
160
	my @chars = ("A".."Z", "a".."z", "1".."0", "(", ")", "-", "_", "*", "^", "!", "[", "]");
161
	my $string;
162
	$string .= $chars[rand @chars] for 1..8;
163
 
164
	my $include_username;
165
	if (!$accountref->{username}) {
166
	  $accountref->{username} = setUsername ($accountref);
167
	  $include_username = "Your Username has also been set to: $accountref->{username}<br><br>";
168
	}
169
 
170
	my $error = updateDBPass ($accountref, $string);
171
 
172
  if (!$error) {
173
  	use PEEPSMailer;
174
  	my $subject = 'WFTDI PEEPS - Password Reset';
175
  	my $body = "Greetings,<br><br>
176
 
177
It appears as though you've requested us to reset your password.  We've done so, and your new password is:<br><br>$string<br><br>$include_username
178
 
179
We'd recommend you log in and change it to your liking at the following link:<br><br>
180
 
181
$pageURL<br><br>
182
 
183
If you didn't make this request, well, you're still the only one who received this email, and this is now your password.  You should probably let us know that someone is messing with you.<br><br>
184
 
185
-WFTDI PEEPS Automation
186
";
187
 
188
  	# send the message
189
  	EmailUser($accountref->{email}, $subject, $body);
190
  }
191
 
192
 
193
print CGI::header();
194
print<<resetPage;
195
 
196
<HTML><HEAD><TITLE>WFTDI PEEPS - Password Reset</TITLE></HEAD>
197
<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
198
<TABLE>
199
	<TR>
200
		<TD align=right><img SRC="/images/wftda-insurance-logo.svg" width="250" height="75"></TD>
201
		<TD align=center valign=middle><b><font size=+3>WFTDI PEEPS<br>Password Reset</font></b></TD>
202
	</TR>
203
	<TR><TD colspan=2><div class="error">$error</div>&nbsp</TD></TR>
204
	<TR><TD colspan=2 align=center>If an account was found, your password was reset and emailed to the address on record.<br>Please check your email (including Spam folders).&nbsp</TD></TR>
205
	<TR><TD colspan=2>&nbsp</TD></TR>
206
	<TR><TD colspan=2 align=center><a href=/>[home]</a>&nbsp</TD></TR>
207
</TABLE>
208
 
209
resetPage
210
}
211
 
212
sub setUsername {
213
  my $account = shift;
214
 
215
  my $dbh = WebDB::connect;
216
  $dbh->do ("insert into authentication (person_id, username, activation, locked) values (?, ?, ?, ?)", undef, $account->{id}, $account->{email}, "active", 0);
217
 
218
  logit($account->{id}, "Setting Username to Email");
219
 
220
  return $account->{email};
221
}
222
 
223
sub sendUsername {
224
	my $account = shift;
225
	my ($pageMSG, $error);
226
	my $pageURL = url;
227
 
228
	$pageURL =~ s|/[^/]+$|/|;
229
 
230
	if ($userref = getUser($account)) {
231
 
232
    if ($userref->{username}) {
233
    	use PEEPSMailer;
234
    	my $subject = 'WFTDI PEEPS - Username';
235
    	my $body = "Greetings,<br><br>
236
 
237
It appears as though you've requested us to send your username.<br><br>
238
 
239
  Username: $userref->{username}
240
 
241
Hopefully this helps you log in.<br><br>
242
 
243
$pageURL<br><br>
244
 
245
If you didn't make this request, well, you're the only one who received this email.<br><br>
246
 
247
-WFTDI PEEPS Automation
248
";
249
 
250
  	# send the message
251
  	EmailUser($userref->{email}, $subject, $body);
252
  	$pageMSG = "Your Username has been emailed to the address on record.<br>Please check your email (including Spam folders).";
253
    } else {
254
      $error = "Oddly, we didn't find a Username.";
255
    }
256
  } else {
257
    $error = "Oddly, we didn't find an account.";
258
  }
259
 
260
 
261
print CGI::header();
262
print<<postSendPage;
263
 
264
<HTML><HEAD><TITLE>WFTDI PEEPS - Password Reset</TITLE></HEAD>
265
<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
266
<TABLE>
267
	<TR>
268
		<TD align=right><img SRC="/images/wftda-insurance-logo.svg" width="250" height="75"></TD>
269
		<TD align=center valign=middle><b><font size=+3>WFTDI PEEPS<br>Password Reset</font></b></TD>
270
	</TR>
271
	<TR><TD colspan=2><div class="error">$error</div>&nbsp</TD></TR>
272
	<TR><TD colspan=2 align=center>$pageMSG &nbsp;</TD></TR>
273
	<TR><TD colspan=2>&nbsp</TD></TR>
274
	<TR><TD colspan=2 align=center><a href=/>[home]</a>&nbsp</TD></TR>
275
</TABLE>
276
 
277
postSendPage
278
}