afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-06-12 01:52 pm

[dw-free] Include email address on invite code management page until used

[commit: http://hg.dwscoalition.org/dw-free/rev/206ca8346bee]

http://bugs.dwscoalition.org/show_bug.cgi?id=604

Store email invite codes were sent to.

Patch by [personal profile] kareila.

Files modified:
  • bin/upgrading/update-db-general.pl
  • cgi-bin/DW/InviteCodes.pm
  • htdocs/admin/invitecodes.bml
  • htdocs/manage/circle/invite.bml
  • htdocs/manage/invitecodes.bml
  • htdocs/manage/invitecodes.bml.text
--------------------------------------------------------------------------------
diff -r 7e8014745b7d -r 206ca8346bee bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl	Thu Jun 11 14:15:26 2009 +0000
+++ b/bin/upgrading/update-db-general.pl	Fri Jun 12 13:52:13 2009 +0000
@@ -1096,6 +1096,7 @@ CREATE TABLE acctcode (
     auth    CHAR(13) NOT NULL,
     timegenerate INT UNSIGNED NOT NULL,
     timesent INT UNSIGNED,
+    email   VARCHAR(255),
     reason  VARCHAR(255),
 
     INDEX (userid),
@@ -4078,6 +4079,11 @@ register_alter(sub {
                   q{ALTER TABLE pp_log ADD COLUMN ip VARCHAR(15) NOT NULL AFTER ppid} );
     }
 
+    unless ( column_type( 'acctcode', 'email' ) ) {
+        do_alter( 'acctcode',
+                  q{ALTER TABLE acctcode ADD COLUMN email VARCHAR(255) AFTER timesent} );
+    }
+
 });
 
 
diff -r 7e8014745b7d -r 206ca8346bee cgi-bin/DW/InviteCodes.pm
--- a/cgi-bin/DW/InviteCodes.pm	Thu Jun 11 14:15:26 2009 +0000
+++ b/cgi-bin/DW/InviteCodes.pm	Fri Jun 12 13:52:13 2009 +0000
@@ -45,12 +45,13 @@ DW::InviteCodes - Invite code management
   my $owner = $object->owner; # userid, not LJ::User object
   my $recipient = $object->recipient; # userid or 0
   my $reason = $object->reason;
+  my $email = $object->email;
   my $timegenerate = $object->timegenerate; # unix timestamp
   my $timesent = $object->timesent; #unix timestamp
   my $is_used = $object->is_used; # true if used to create an account
 
   # Mark the invite code as sent
-  $code->send_code;
+  $code->send_code( email => $email );
 
   # Mark the invite code as used
   $code->use_code( user => LJ::load_user('new') );
@@ -60,7 +61,7 @@ use strict;
 use strict;
 use warnings;
 
-use fields qw(acid userid rcptid auth reason timegenerate timesent);
+use fields qw(acid userid rcptid auth reason timegenerate timesent email);
 
 use constant { AUTH_LEN => 13, ACID_LEN => 7 };
 use constant DIGITS => qw(A B C D E F G H J K L M N P Q R S T U V W X Y Z 2 3 4 5 6 7 8 9);
@@ -200,9 +201,10 @@ sub use_code {
     return 1; # 1 means success? Needs error return in that case.
 }
 
-=head2 C<< $object->send_code >>
+=head2 C<< $object->send_code ( [ email => $email ] ) >>
 
 Marks an invite code as having been sent. The code may or may not have been used to create a new account.
+Make sure if passing email to validate first!
 
 =cut
 
@@ -210,8 +212,8 @@ sub send_code {
     my ($self, %opts) = @_;
     my $dbh = LJ::get_db_writer();
 
-    $dbh->do( "UPDATE acctcode SET timesent=UNIX_TIMESTAMP() WHERE acid=?",
-        undef, $self->{acid} );
+    $dbh->do( "UPDATE acctcode SET timesent=UNIX_TIMESTAMP(), email=? WHERE acid=?",
+        undef, $opts{email}, $self->{acid} );
 
     return 1; # 1 means success? Needs error return in that case.
 }
@@ -229,7 +231,7 @@ sub new {
     return undef unless length( $opts{code} ) == CODE_LEN;
 
     my ($acid, $auth) = $class->decode( $opts{code} );
-    my $ac = $dbr->selectrow_hashref( "SELECT acid, userid, rcptid, auth, reason, timegenerate, timesent FROM acctcode ".
+    my $ac = $dbr->selectrow_hashref( "SELECT acid, userid, rcptid, auth, reason, timegenerate, timesent, email FROM acctcode ".
                                       "WHERE acid=? AND auth=?",
                                       undef, $acid, $auth);
 
@@ -310,7 +312,7 @@ sub load_by {
     my $dbr = LJ::get_db_reader();
 
     my $unused_sql = $only_load_unused ? "AND rcptid=0" : "";
-    my $sth = $dbr->prepare( "SELECT acid, userid, rcptid, auth, reason, timegenerate, timesent FROM acctcode WHERE $field = ? $unused_sql" )
+    my $sth = $dbr->prepare( "SELECT acid, userid, rcptid, auth, reason, timegenerate, timesent, email FROM acctcode WHERE $field = ? $unused_sql" )
         or die "Unable to retrieve invite codes by $field: " . $dbr->errstr;
 
     $sth->execute($userid + 0)
@@ -399,6 +401,18 @@ sub timesent {
     my ($self) = @_;
 
     return $self->{timesent};
+}
+
+=head2 C<< $object->email >>
+
+Returns the email address the invite code was sent to through the interface. The code may or may not have been used since.
+
+=cut
+
+sub email {
+    my ($self) = @_;
+
+    return $self->{email};
 }
 
 =head2 C<< $object->is_used >>
diff -r 7e8014745b7d -r 206ca8346bee htdocs/admin/invitecodes.bml
--- a/htdocs/admin/invitecodes.bml	Thu Jun 11 14:15:26 2009 +0000
+++ b/htdocs/admin/invitecodes.bml	Fri Jun 12 13:52:13 2009 +0000
@@ -57,7 +57,7 @@ sub display_codes {
 sub display_codes {
     my ($account, @codes) = @_;
 
-    my $ret = "<table border='1' cellpadding='5'><tr><th>Code</th><th>Owner</th><th>Recipient</th><th>Reason</th><th>Date generated</th><th>Date sent</th><th>Date used</th></tr>";
+    my $ret = "<table border='1' cellpadding='5'><tr><th>Code</th><th>Owner</th><th>Recipient</th><th>Reason</th><th>Date generated</th><th>Date sent</th><th>Date used</th><th>Email</th></tr>";
 
     foreach my $code ( @codes ) {
         my $owner = $code->owner == $account->id ? $account : LJ::load_userid( $code->owner );
@@ -70,6 +70,7 @@ sub display_codes {
         $ret .= "<td>" . LJ::time_to_http( $code->timegenerate). "</td>";
         $ret .= "<td>" . ( $code->timesent ? LJ::time_to_http( $code->timesent ) : "" ) . "</td>";
         $ret .= "<td>" . ( $code->is_used ? LJ::time_to_http( $recipient->timecreate ) : "" ) . "</td>";
+        $ret .= "<td>" . $code->email . "</td>";
         $ret .= "</tr>";
     }
     $ret .= "</table>";
diff -r 7e8014745b7d -r 206ca8346bee htdocs/manage/circle/invite.bml
--- a/htdocs/manage/circle/invite.bml	Thu Jun 11 14:15:26 2009 +0000
+++ b/htdocs/manage/circle/invite.bml	Fri Jun 12 13:52:13 2009 +0000
@@ -162,7 +162,7 @@
             if ( $LJ::USE_ACCT_CODES ) {
                 # mark an invite code as sent
                 my $invite_obj = DW::InviteCodes->new( code => $code );
-                $invite_obj->send_code;
+                $invite_obj->send_code( email => $email );
 
                 $body .= "<?standout " . BML::ml('.success.code', { email  => $email, invitecode => $code }) . " standout?>";
 
diff -r 7e8014745b7d -r 206ca8346bee htdocs/manage/invitecodes.bml
--- a/htdocs/manage/invitecodes.bml	Thu Jun 11 14:15:26 2009 +0000
+++ b/htdocs/manage/invitecodes.bml	Fri Jun 12 13:52:13 2009 +0000
@@ -25,7 +25,7 @@ body<=
     my @invitecodes = DW::InviteCodes->by_owner( userid => $remote->id );
     
     if ( @invitecodes ) {
-        $ret .= "<table class='invitecodes'><tr><th>$ML{'.header.code'}</th><th>$ML{'.header.recipient'}</th><th>$ML{'.header.sent'}</th></tr>";
+        $ret .= "<table class='invitecodes'><tr><th>$ML{'.header.code'}</th><th>$ML{'.header.recipient'}</th><th width='200'>$ML{'.header.sent'}</th><th>$ML{'.header.email'}</th></tr>";
     
         foreach my $code ( @invitecodes ) {
             $ret .= "<tr>";
@@ -47,6 +47,10 @@ body<=
             $ret .= LJ::time_to_http( $code->timesent ) if $code->timesent;
             $ret .= "</td>";
             
+            $ret .= "<td>";
+            $ret .= $code->email;
+            $ret .= "</td>";
+            
             $ret .= "</tr>";
         }
     
diff -r 7e8014745b7d -r 206ca8346bee htdocs/manage/invitecodes.bml.text
--- a/htdocs/manage/invitecodes.bml.text	Thu Jun 11 14:15:26 2009 +0000
+++ b/htdocs/manage/invitecodes.bml.text	Fri Jun 12 13:52:13 2009 +0000
@@ -15,8 +15,11 @@
 
 .noinvitecodes=You have no invite codes.
 
-.header.code=Code
+.header.code=Code:
 
-.header.recipient=Recipient
+.header.email=Sent to email:
 
-.header.sent=Sent on
+.header.recipient=Recipient:
+
+.header.sent=Sent on:
+
--------------------------------------------------------------------------------
cesy: "Cesy" - An old-fashioned quill and ink (Default)

Storing emails that invite codes were sent to

[personal profile] cesy 2009-06-12 02:08 pm (UTC)(link)
Yay!
mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)

[staff profile] mark 2009-06-12 05:09 pm (UTC)(link)
This is actually:

http://bugs.dwscoalition.org/show_bug.cgi?id=604

(Just annotating.)
ninetydegrees: Art & Text: heart with aroace colors, "you are loved" (Default)

[personal profile] ninetydegrees 2009-06-13 11:03 am (UTC)(link)
Thank you!