fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2012-02-24 07:35 am

[dw-free] Unable to create account: "too many codes" error, even though we've turned off i

[commit: http://hg.dwscoalition.org/dw-free/rev/92a2912b7916]

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

Start with the assumption that rate limiting is okay, and only change to
false if the check proves otherwise -- so that we don't run into the rate
limiting on post. Also limit rate limiting to when the user has a code
argument.

Patch by [personal profile] fu.

Files modified:
  • htdocs/create.bml
--------------------------------------------------------------------------------
diff -r 43c0ae14d11f -r 92a2912b7916 htdocs/create.bml
--- a/htdocs/create.bml	Fri Feb 24 13:26:03 2012 +0800
+++ b/htdocs/create.bml	Fri Feb 24 15:35:04 2012 +0800
@@ -37,7 +37,10 @@
     my %from_post;
     my $code_valid = $LJ::USE_ACCT_CODES ? 0 : 1;
     my $code;
-    my $rate_ok;
+
+    # start out saying we're okay; we'll modify this if we're actually checking codes later
+    my $rate_ok = 1;
+
     if ( LJ::did_post() ) {
         my $post_args = DW::Request->get->post_args;
         my $captcha = DW::Captcha->new( 'create' );
@@ -48,12 +51,13 @@
         # we always need the code, because it might contain paid time
         $code = LJ::trim( $GET{code} );
 
-        # but we don't always need to block the registration
+        # and we always do rate limiting if we have a code
+        $rate_ok = DW::InviteCodes->check_rate if $code;
+
+        # but we don't always need to block the registration on the validity of the code
+        # (if we have an invalid code, but we do don't require codes to open an account, just fail silently)
         $code_valid = DW::InviteCodes->check_code( code => $code )
             if $LJ::USE_ACCT_CODES;
-
-        # rate limiting
-        $rate_ok = DW::InviteCodes->check_rate;
     }
 
     my $ret;
--------------------------------------------------------------------------------