mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-03-03 09:07 am

[dw-free] Need to add reserved usernames

[commit: http://hg.dwscoalition.org/dw-free/rev/13d855c380d5]

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

Make list of protected usernames editable on the site. 9 minutes.

Patch by [staff profile] mark.

Files modified:
  • cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
  • cgi-bin/LJ/ConfCheck/General.pm
  • cgi-bin/LJ/CreatePage.pm
  • cgi-bin/LJ/User.pm
  • cgi-bin/ljdefaults.pl
  • htdocs/community/create.bml
  • htdocs/create.bml
  • htdocs/inc/reserved-usernames
  • htdocs/syn/index.bml
--------------------------------------------------------------------------------
diff -r 20f8b0f4a907 -r 13d855c380d5 cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Mon Mar 02 17:02:07 2009 -0800
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Tue Mar 03 09:06:58 2009 +0000
@@ -273,12 +273,10 @@ sub get_feed_account_from_url {
         return undef unless $acct;
 
         # since we're creating, let's validate this against the deny list
-        foreach my $re ( '^system$', @LJ::PROTECTED_USERNAMES ) {
-            # FIXME: probably need to error nicely here, as we're not creating
-            # the feed that the user is expecting...
-            return undef
-                if $acct =~ /$re/;
-        }
+        # FIXME: probably need to error nicely here, as we're not creating
+        # the feed that the user is expecting...
+        return undef
+            if LJ::User->is_protected_username( $acct );
 
         # append _feed here, username should be valid by this point.
         $acct .= "_feed";
diff -r 20f8b0f4a907 -r 13d855c380d5 cgi-bin/LJ/ConfCheck/General.pm
--- a/cgi-bin/LJ/ConfCheck/General.pm	Mon Mar 02 17:02:07 2009 -0800
+++ b/cgi-bin/LJ/ConfCheck/General.pm	Tue Mar 03 09:06:58 2009 +0000
@@ -757,9 +757,6 @@ add_conf('%MOGILEFS_CONFIG',
 add_conf('%MOGILEFS_CONFIG',
          type => '',
          des => "");
-add_conf('@PROTECTED_USERNAMES',
-         type => '',
-         des => "");
 add_conf('%PORTAL_DEFAULTBOXSTATES',
          type => '',
          des => "");
diff -r 20f8b0f4a907 -r 13d855c380d5 cgi-bin/LJ/CreatePage.pm
--- a/cgi-bin/LJ/CreatePage.pm	Mon Mar 02 17:02:07 2009 -0800
+++ b/cgi-bin/LJ/CreatePage.pm	Tue Mar 03 09:06:58 2009 +0000
@@ -57,14 +57,9 @@ sub verify_username {
         }
     }
 
-    foreach my $re ("^system\$", @LJ::PROTECTED_USERNAMES) {
-        next unless ($user =~ /$re/);
-
-        # you can give people sharedjournal priv ahead of time to create
-        # reserved communities:
-        next if LJ::check_priv(LJ::get_remote(), "sharedjournal", $user);
-        $error = LJ::Widget::CreateAccount->ml('widget.createaccount.error.username.reserved');
-    }
+    # don't allow protected usernames
+    $error = LJ::Widget::CreateAccount->ml('widget.createaccount.error.username.reserved')
+        if LJ::User->is_protected_username( $user );
 
     $error = LJ::Widget::CreateAccount->ml('widget.createaccount.error.username.inuse') if $in_use;
 
diff -r 20f8b0f4a907 -r 13d855c380d5 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Mon Mar 02 17:02:07 2009 -0800
+++ b/cgi-bin/LJ/User.pm	Tue Mar 03 09:06:58 2009 +0000
@@ -320,11 +320,16 @@ sub delete_and_purge_completely {
 }
 
 
+# checks against the file containing our regular expressions to determine if a
+# given username is disallowed
 sub is_protected_username {
-    my ($class, $username) = @_;
-    foreach my $re (@LJ::PROTECTED_USERNAMES) {
+    my ( $class, $username ) = @_;
+
+    my @res = grep { $_ } split( /\r?\n/, LJ::load_include( 'reserved-usernames' ) );
+    foreach my $re ( @res ) {
         return 1 if $username =~ /$re/;
     }
+
     return 0;
 }
 
diff -r 20f8b0f4a907 -r 13d855c380d5 cgi-bin/ljdefaults.pl
--- a/cgi-bin/ljdefaults.pl	Mon Mar 02 17:02:07 2009 -0800
+++ b/cgi-bin/ljdefaults.pl	Tue Mar 03 09:06:58 2009 +0000
@@ -343,10 +343,6 @@
                          );
     }
 
-    unless (scalar @PROTECTED_USERNAMES) {
-        @PROTECTED_USERNAMES = ("^ex_", "^ext_", "^s_", "^_", '_$', '__');
-    }
-
     $USERPROP_DEF{'blob_clusterid'} ||= 1;
 
     # setup default limits for mogilefs classes
diff -r 20f8b0f4a907 -r 13d855c380d5 htdocs/community/create.bml
--- a/htdocs/community/create.bml	Mon Mar 02 17:02:07 2009 -0800
+++ b/htdocs/community/create.bml	Tue Mar 03 09:06:58 2009 +0000
@@ -60,15 +60,9 @@ SUBMIT:
         $error = "$ML{'error.usernameinvalid'}" if $POST{user} && !$user;
         $error = "$ML{'.error.username.mustenter'}" unless $POST{user};
 
-        foreach my $re ("^system\$", @LJ::PROTECTED_USERNAMES) {
-            next unless $user =~ /$re/;
-
-            # you can give people sharedjournal priv ahead of time to create
-            # reserved communities:
-            next if LJ::check_priv($remote, "sharedjournal", $user);
-
-            $error = "$ML{'.error.username.reserved'}";
-        }
+        # disallow creating communities matched against the deny list
+        $error = "$ML{'.error.username.reserved'}"
+            if LJ::User->is_protected_username( $user );
 
         my $second_submit;
         my $u = LJ::load_user($user);
diff -r 20f8b0f4a907 -r 13d855c380d5 htdocs/create.bml
--- a/htdocs/create.bml	Mon Mar 02 17:02:07 2009 -0800
+++ b/htdocs/create.bml	Tue Mar 03 09:06:58 2009 +0000
@@ -151,15 +151,10 @@ if ( $LJ::HUMAN_CHECK{create} && $mode e
      unless ($POST{'user'}) {
          $errors{'username'} = "$ML{'.error.username.mustenter'}";
      }
-     foreach my $re ("^system\$", @LJ::PROTECTED_USERNAMES) {
-         next unless ($user =~ /$re/);
 
-         # you can give people sharedjournal priv ahead of time to create
-         # reserved communities:
-         next if LJ::check_priv($remote, "sharedjournal", $user);
 
-         $errors{'username'} = "$ML{'.error.username.reserved'}";
-     }
+     $errors{username} = $ML{'.error.username.reserved'}
+        if LJ::User->is_protected_username( $user );
 
      # see if they're confused and entered a valid account code
      # for their username (happens often)
diff -r 20f8b0f4a907 -r 13d855c380d5 htdocs/inc/reserved-usernames
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/inc/reserved-usernames	Tue Mar 03 09:06:58 2009 +0000
@@ -0,0 +1,8 @@
+^www$
+^dw_
+^ex_
+^ext_
+^s_
+^_
+_$
+__
diff -r 20f8b0f4a907 -r 13d855c380d5 htdocs/syn/index.bml
--- a/htdocs/syn/index.bml	Mon Mar 02 17:02:07 2009 -0800
+++ b/htdocs/syn/index.bml	Tue Mar 03 09:06:58 2009 +0000
@@ -34,10 +34,8 @@ body<=
         if ($acct ne "") {
             return $error->($ML{'.invalid.accountname'})
                 if $acct && $acct !~ /^\w{3,20}$/; # This needs to be 5 less then the username limt.
-            foreach my $re ("^system\$", @LJ::PROTECTED_USERNAMES) {
-                next unless ($acct =~ /$re/);
-                return $error->($ML{'.invalid.reserved'});
-            }
+            return $error->( $ML{'.invalid.reserved'} )
+                if LJ::User->is_protected_username( $acct );
             # Postpend _feed here, username should be valid by this point.
             $acct .= "_feed";
         }
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org