User: sits    
  Date: 08/09/06 04:33:06

  Modified:    lib/Codestriker/Model User.pm
               bin      install.pl
               .        codestriker.conf
  Log:
  Also handle situation here an "admin upgrade" occurs for an existing user.
  
  
  
  Index: User.pm
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Model/User.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- User.pm   6 Sep 2008 11:12:31 -0000       1.1
  +++ User.pm   6 Sep 2008 11:33:06 -0000       1.2
  @@ -45,6 +45,44 @@
       return $self;
   }
   
  +# Update an existing user record with a new password.
  +sub update_password {
  +    my ($self, $new_password) = @_;
  +
  +    my $password_hash = _hash_password($new_password);
  +    my $dbh = Codestriker::DB::DBI->get_connection();
  +    eval {
  +        my $update_user =
  +          $dbh->prepare_cached('UPDATE usertable SET password_hash = ? ' .
  +                               'WHERE email = ?');
  +        $update_user->execute($password_hash, $self->{email});
  +    };
  +    my $success = $@ ? 0 : 1;
  +
  +    Codestriker::DB::DBI->release_connection($dbh, $success);
  +    die $dbh->errstr unless $success;
  +
  +    $self->{password_hash} = $password_hash;
  +}
  +
  +# Update an existing user record with new admin status.
  +sub update_admin {
  +    my ($self, $new_admin) = @_;
  +
  +    my $dbh = Codestriker::DB::DBI->get_connection();
  +    eval {
  +        my $update_user =
  +          $dbh->prepare_cached('UPDATE usertable SET admin = ? ' .
  +                               'WHERE email = ?');
  +        $update_user->execute($new_admin, $self->{email});
  +    };
  +    my $success = $@ ? 0 : 1;
  +
  +    Codestriker::DB::DBI->release_connection($dbh, $success);
  +    die $dbh->errstr unless $success;
  +
  +    $self->{admin} = $new_admin;
  +}
   
   # Create a new user into the database with all of the specified properties.
   # Return the new password which has been assigned to the user.
  
  
  
  
  
  Index: install.pl
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/bin/install.pl,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- install.pl        6 Sep 2008 11:12:31 -0000       1.23
  +++ install.pl        6 Sep 2008 11:33:06 -0000       1.24
  @@ -55,6 +55,7 @@
   eval("use Codestriker::FileParser::UnknownFormat");
   eval("use Codestriker::Model::File");
   eval("use Codestriker::Model::User");
  +use Codestriker::Model::User;
   
   # Set this variables, to avoid compilation warnings below.
   $Codestriker::COMMENT_SUBMITTED = 0;
  @@ -1077,6 +1078,14 @@
               Codestriker::Model::User->create($admin_user, 1);
               # TODO: consider sending email with password details.
               print "Done\n";
  +        } else {
  +            # Existing user, check if they are an admin already.
  +            my $user = Codestriker::Model::User->new($admin_user);
  +            if (! $user->{admin}) {
  +                print "Upgrading non-admin user $admin_user to admin...\n";
  +                $user->update_admin(1);
  +                print "Done\n";
  +            }
           }
       }
   }
  
  
  
  
  
  Index: codestriker.conf
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/codestriker.conf,v
  retrieving revision 1.105
  retrieving revision 1.106
  diff -u -r1.105 -r1.106
  --- codestriker.conf  6 Sep 2008 11:12:31 -0000       1.105
  +++ codestriker.conf  6 Sep 2008 11:33:06 -0000       1.106
  @@ -38,9 +38,9 @@
   # be able to create/edit/delete projects.  If no admin user is defined
   # then no login system will be used, and all users will be effectively
   # admin users.
  -#$admin_users = [ '[EMAIL PROTECTED]' ];
  +$admin_users = [ '[EMAIL PROTECTED]' ];
   #$admin_users = [ '[EMAIL PROTECTED]', '[EMAIL PROTECTED]' ];
  -$admin_users = [];
  +#$admin_users = [];
   
   # Location of the mailing host.  This is used when sending out codestriker
   # comments.
  
  
  

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to