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] changelog2011-12-29 06:48 am

[dw-free] Update the create-account helper script so it can create communities

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

Update the create-account helper script so it can create communities

Patch by [staff profile] mark.

Files modified:
  • bin/create-account
--------------------------------------------------------------------------------
diff -r 75287c8bf228 -r fb24395b0f38 bin/create-account
--- a/bin/create-account	Thu Dec 29 14:13:32 2011 +0800
+++ b/bin/create-account	Thu Dec 29 06:52:33 2011 +0000
@@ -19,31 +19,41 @@
 
 use Getopt::Long;
 
-my ( $user, $email, $pass );
+my ( $user, $email, $pass, $comm, $admin );
 GetOptions(
         'user=s' => \$user,
         'password=s' => \$pass,
         'email=s' => \$email,
+        'community' => \$comm,
+        'admin=s' => \$admin,
     ) or die "usage: $0 -u USERNAME -e EMAIL\n";
-die "usage: $0 -u USERNAME -e EMAIL [-p PASSWORD]\n"
-    unless $user && $email;
+die "usage: $0 -u USERNAME [-e EMAIL -p PASSWORD|--community --admin=USER]\n"
+    unless (!$comm && $user && $email) || ($comm && $user && $admin);
 
 $user = LJ::canonical_username( $user );
 die "Username invalid\n"
     unless $user;
-die "Email invalid\n"
-    unless $email && $email =~ /^[^@]+@[^@]+\.\w+$/;
 
 LJ::MemCache::delete( 'uidof:' . $user );
 my $u2 = LJ::load_user( $user )
     and die "User already exists\n";
 
-my $password = $pass || '';
-unless ( $password ) {
-    $password .= substr( 'abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ0123456789', int(rand()*62), 1 ) for 1..10;
+if ( $comm ) {
+    my $adminu = LJ::load_user($admin)
+        or die "Can't load admin user\n";
+
+    my $u = LJ::User->create_community( user => $user, email => $email, admin_userid => $adminu->id );
+    print "User: $u->{user}($u->{userid}) created with maintainer $adminu->{user}.\n";
+} else {
+    die "Email invalid\n"
+        unless $email && $email =~ /^[^@]+@[^@]+\.\w+$/;
+
+    my $password = $pass || '';
+    unless ( $password ) {
+        $password .= substr( 'abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ0123456789', int(rand()*62), 1 ) for 1..10;
+    }
+
+    my $u = LJ::User->create_personal( user => $user, email => $email, password => $password )
+        or die "unable to create account?\n";
+    print "User: $u->{user}($u->{userid}) created with password $password.\n";
 }
-
-my $u = LJ::User->create_personal( user => $user, email => $email, password => $password )
-    or die "unable to create account?\n";
-
-print "User: $u->{user}($u->{userid}) created with password $password.\n";
--------------------------------------------------------------------------------

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