Subversion Repositories PEEPS

Rev

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