From: naoki i. <am...@us...> - 2008-04-16 13:08:06
|
Update of /cvsroot/popfile/engine/Classifier In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22400/Classifier Modified Files: Bayes.pm Log Message: Change Log 1. Added the UI to rename user's name UI/HTML.pm Classifier/Bayes.pm POPFile/API.pm skins/default/users-page.thtml languages/English.msg languages/Nihongo.msg tests/TestBayes.tst 2. Save the current piddir and restore in the utility scripts bayes.pl insert.pl pipe.pl 3. TestXMLRPC's child process (xmlrpc server) now terminates tests/TestXMLRPC.tst 4. Use the place holders in preparing SQL statements UI/HTML.pm POPFile/History.pm 5. Copy the global language setting to the new user's default language Classifier/Bayes.pm 6. New script to import old database to new database import.pl import.pl - import user data into the new database Usage: import.pl <old_user_dir> <user> [<newuser>] <old_user_dir> The path to the user data to import <user> The name of the user to import from Use 'admin' when upgrading from v1 <newuser> The name of the user to import into (optional) If not specified, assume newuser=user 7. Added multi user support tests tests/TestHistory.tst Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS TestHTML PASS * TestHTTP PASS TestIMAP PASS TestInsertScript PASS * TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 PASS TestProxy PASS TestWordMangle PASS TestXMLRPC PASS * : TODO : needs to add tests for multi user support Index: Bayes.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v retrieving revision 1.365 retrieving revision 1.366 diff -C2 -d -r1.365 -r1.366 *** Bayes.pm 13 Apr 2008 03:08:09 -0000 1.365 --- Bayes.pm 16 Apr 2008 13:08:04 -0000 1.366 *************** *** 1264,1271 **** users.id = buckets.userid and magnets.bucketid = buckets.id and ! magnet_types.mtype = '$type' and magnets.mtid = magnet_types.id order by magnets.val;" ); # PROFILE BLOCK STOP ! $h->execute; while ( my $row = $h->fetchrow_arrayref ) { push @magnets, [$row->[0], $row->[1]]; --- 1264,1271 ---- users.id = buckets.userid and magnets.bucketid = buckets.id and ! magnet_types.mtype = ? and magnets.mtid = magnet_types.id order by magnets.val;" ); # PROFILE BLOCK STOP ! $h->execute( $type ); while ( my $row = $h->fetchrow_arrayref ) { push @magnets, [$row->[0], $row->[1]]; *************** *** 2919,2924 **** # If user is an admin then grab the accounts for the user requested ! my $h = $self->db_()->prepare( "select account from accounts where userid = $id;" ); ! $h->execute; my @accounts; while ( my $row = $h->fetchrow_arrayref ) { --- 2919,2924 ---- # If user is an admin then grab the accounts for the user requested ! my $h = $self->db_()->prepare( "select account from accounts where userid = ?;" ); ! $h->execute( $id ); my @accounts; while ( my $row = $h->fetchrow_arrayref ) { *************** *** 2965,2971 **** } ! $account = $self->db_()->quote( "$module:$account" ); ! my $h = $self->db_()->prepare( "insert into accounts ( userid, account ) values ( $id, $account );" ); ! if ( !defined( $h->execute ) ) { return 0; } --- 2965,2970 ---- } ! my $h = $self->db_()->prepare( "insert into accounts ( userid, account ) values ( ?, ? );" ); ! if ( !defined( $h->execute( $id, "$module:$account" ) ) ) { return 0; } *************** *** 3470,3474 **** if ( !$self->is_admin_session( $session ) ) { ! return ( undef, undef ); } --- 3469,3473 ---- if ( !$self->is_admin_session( $session ) ) { ! return undef; } *************** *** 3639,3642 **** --- 3638,3646 ---- $self->db_()->do( "insert into buckets ( name, pseudo, userid ) values ( 'unclassified', 1, $id );" ); + + # Copy the global language setting to the user's language setting + + $self->user_module_config_( $id, 'html', 'language', + $self->global_config_( 'language' ) ); } *************** *** 3668,3671 **** --- 3672,3732 ---- #---------------------------------------------------------------------------- # + # rename_user (ADMIN ONLY) + # + # Renames an existing user + # + # $session A valid session ID for an administrator + # $user The name of the user to rename + # $newname The new name for the user + # + # Returns 0 for sucess, undef for wrong permissions and 1 for newname + # already exists, 2 means tried to rename 'admin' or user does not exist + # + #---------------------------------------------------------------------------- + sub rename_user + { + my ( $self, $session, $user, $newname ) = @_; + + my $userid = $self->valid_session_key__( $session ); + return undef if ( !defined( $userid ) ); + + if ( !defined( $user ) || !defined( $newname ) ) { + return undef; + } + + # Check that this user is an administrator + + if ( !$self->is_admin_session( $session ) ) { + return undef; + } + + # Check that the user is 'admin' + + my $id = $self->get_user_id( $session, $user ); + if ( defined( $id ) ) { + if ( $id == 1 ) { + return ( 2, undef ); + } else { + if ( defined( $self->get_user_id( $session, $newname ) ) ) { + return ( 1, undef ); + } + + my $password = $self->generate_users_password(); + + my $password_hash = md5_hex( $newname . '__popfile__' . $password ); + my $h = $self->db_()->prepare( "update users set name = ?, password = ? where id = ?" ); + $h->execute( $newname, $password_hash, $id ); + $h->finish; + + return ( 0, $password ); + } + } + + return ( 2, undef ); + } + + + #---------------------------------------------------------------------------- + # # remove_user (ADMIN ONLY) # *************** *** 3984,3988 **** my $userid = $self->valid_session_key__( $session ); ! return undef if ( !defined( $userid ) ); # Check that this user is an administrator --- 4045,4049 ---- my $userid = $self->valid_session_key__( $session ); ! return undef if ( !defined( $userid ) || !defined( $user ) ); # Check that this user is an administrator *************** *** 3992,3998 **** } ! my $quoted_user = $self->db_()->quote( $user ); ! my $h = $self->db_()->prepare( "select id from users where name = $quoted_user;" ); ! $h->execute; if ( my $row = $h->fetchrow_arrayref ) { $h->finish; --- 4053,4058 ---- } ! my $h = $self->db_()->prepare( "select id from users where name = ?;" ); ! $h->execute( $user ); if ( my $row = $h->fetchrow_arrayref ) { $h->finish; *************** *** 4093,4098 **** return undef if ( !defined( $userid ) ); ! my $h = $self->db_()->prepare( "select name from users where id = $id;" ); ! $h->execute; if ( my $row = $h->fetchrow_arrayref ) { $h->finish; --- 4153,4158 ---- return undef if ( !defined( $userid ) ); ! my $h = $self->db_()->prepare( "select name from users where id = ?;" ); ! $h->execute( $id ); if ( my $row = $h->fetchrow_arrayref ) { $h->finish; *************** *** 4505,4513 **** where magnet_types.id = magnets.mtid and magnets.bucketid = buckets.id and ! buckets.id = $bucketid group by magnet_types.mtype order by magnet_types.mtype;" ); ! $h->execute; while ( my $row = $h->fetchrow_arrayref ) { push @result, ($row->[0]); --- 4565,4573 ---- where magnet_types.id = magnets.mtid and magnets.bucketid = buckets.id and ! buckets.id = ? group by magnet_types.mtype order by magnet_types.mtype;" ); ! $h->execute( $bucketid ); while ( my $row = $h->fetchrow_arrayref ) { push @result, ($row->[0]); *************** *** 4589,4595 **** magnets.id != 0 and magnet_types.id = magnets.mtid and ! magnet_types.mtype = '$type' order by magnets.val;" ); ! $h->execute; while ( my $row = $h->fetchrow_arrayref ) { push @result, ($row->[0]); --- 4649,4655 ---- magnets.id != 0 and magnet_types.id = magnets.mtid and ! magnet_types.mtype = ? order by magnets.val;" ); ! $h->execute( $type ); while ( my $row = $h->fetchrow_arrayref ) { push @result, ($row->[0]); *************** *** 4650,4654 **** my %result; ! my $h = $self->db_()->prepare( "select magnet_types.mtype, magnet_types.header from magnet_types order by mtype;" ); $h->execute; --- 4710,4716 ---- my %result; ! my $h = $self->db_()->prepare( ! "select magnet_types.mtype, magnet_types.header ! from magnet_types order by mtype;" ); $h->execute; |