[livejournal] r15946: Log it when a password reset email is re...

Nov 24, 2009 11:36


Committer: ailyinLog it when a password reset email is requested.

U trunk/cgi-bin/LJ/User.pm
U trunk/htdocs/admin/userlog.bml
U trunk/htdocs/lostinfo.bml

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm 2009-11-24 11:16:38 UTC (rev 15945)
+++ trunk/cgi-bin/LJ/User.pm 2009-11-24 11:36:54 UTC (rev 15946)
@@ -2372,6 +2372,59 @@
undef, $u->id, $email);
}

+# my $u = LJ::want_user(12);
+# my $data = $u->get_email_data('test@test.ru');
+# print $data->{'email_state'}; # email status if test@test.ru is the
+# # current email; "P" otherwise
+# print $data->{'time'}; # time when that email was first added to the account
+sub get_email_data {
+ my ($u, $email) = @_;
+
+ return undef unless $u && $email;
+
+ warn $u->email_status;
+
+ my $dbh = LJ::get_db_reader();
+ if (lc($email) eq lc($u->email_raw)) {
+ my ($time) = $dbh->selectrow_array(
+ 'SELECT UNIX_TIMESTAMP(MAX(timechange)) FROM infohistory '.
+ 'WHERE userid=? AND what="email"', undef,
+ $u->id);
+
+ return {
+ 'email_state' => $u->email_status,
+ 'time' => $time,
+ };
+ } elsif ($u->can_receive_password($email)) {
+ # well, the logic here is complicated
+ # infohistory only stores the date when the address was changed FROM
+ # the one given to something else; as such, we need to get that record,
+ # skip it, and then get the timestamp of last email change before that
+
+ my ($timechanged) = $dbh->selectrow_array(
+ 'SELECT MIN(timechange) FROM infohistory '.
+ 'WHERE userid=? AND what="email" '.
+ 'AND oldvalue=? AND other="A"', undef,
+ $u->id, $email
+ );
+
+ my @time_row = $dbh->selectrow_array(
+ 'SELECT UNIX_TIMESTAMP(MAX(timechange)) FROM infohistory '.
+ 'WHERE userid=? AND what="email" AND timechangeid, $timechanged
+ );
+
+ # if there was no email changes before that one, assume that the
+ # address was added when the user registered
+ my $time = @time_row ? $time_row[0] : $u->timecreate;
+
+ return {
+ 'email_state' => 'P',
+ 'time' => $time,
+ };
+ }
+}
+
sub share_contactinfo {
my ($u, $remote) = @_;

Modified: trunk/htdocs/admin/userlog.bml
===================================================================
--- trunk/htdocs/admin/userlog.bml 2009-11-24 11:16:38 UTC (rev 15945)
+++ trunk/htdocs/admin/userlog.bml 2009-11-24 11:36:54 UTC (rev 15946)
@@ -107,6 +107,16 @@
# TODO: parse out e_unixtime and s_unixtime and display?
} elsif ($row->{action} eq 'delete_userpic') {
$action = "Deleted userpic #$extra->{picid}";
+ } elsif ($row->{action} eq 'pwd_reset_req') {
+ my $email = $extra->{email};
+ my $email_state = {
+ 'A' => 'current, validated',
+ 'T' => 'current, transitioning',
+ 'N' => 'current, non-validated',
+ 'P' => 'previously-validated'
+ }->{$extra->{email_state}};
+ my $time = scalar(localtime($extra->{time}));
+ $action = "Requested a password reset email to $email; $email_state; added on $time.";
} elsif (my $info = LJ::run_hook('userlog_rows', $row)) {
$action = $info;
} else {

Modified: trunk/htdocs/lostinfo.bml
===================================================================
--- trunk/htdocs/lostinfo.bml 2009-11-24 11:16:38 UTC (rev 15945)
+++ trunk/htdocs/lostinfo.bml 2009-11-24 11:36:54 UTC (rev 15946)
@@ -194,6 +194,13 @@
'rooturl' => "$LJ::SITEROOT/" }) . "\n";
}

+ my $data = $u->get_email_data($email);
+ $u->log_event('pwd_reset_req', {
+ email => $email,
+ email_state => $data->{'email_state'},
+ time => $data->{'time'},
+ });
+
LJ::send_mail({
'to' => $email,
'from' => $LJ::ADMIN_EMAIL,

Previous post Next post
Up