From c4287162c4fb16e5b85a103aabbbbe7a7eebe4c7 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Sun, 17 Apr 2011 01:04:23 +0200 Subject: [PATCH] Some work on the fancy user management --- admin/ajax/creategroup.php | 17 +++--------- admin/ajax/createuser.php | 7 ++--- admin/ajax/removegroup.php | 25 +++++++++++++++++ admin/ajax/removeuser.php | 25 +++++++++++++++++ admin/js/users.js | 57 +++++++++++++++++++++++++++++++------- admin/templates/users.php | 21 +++++++------- lib/Group/backend.php | 7 +++++ lib/Group/database.php | 12 ++++++++ lib/User/backend.php | 6 ++++ lib/User/database.php | 12 ++++++++ lib/app.php | 4 --- lib/filestorage.php | 7 +++-- lib/group.php | 18 ++++++++++++ lib/user.php | 8 ++++++ 14 files changed, 181 insertions(+), 45 deletions(-) create mode 100644 admin/ajax/removegroup.php create mode 100644 admin/ajax/removeuser.php diff --git a/admin/ajax/creategroup.php b/admin/ajax/creategroup.php index ab99d2a5be..bfa4099b88 100644 --- a/admin/ajax/creategroup.php +++ b/admin/ajax/creategroup.php @@ -12,23 +12,14 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } -$groups = array(); -if( isset( $_POST["groups"] )){ - $groups = $_POST["groups"]; -} -$username = $_POST["username"]; -$password = $_POST["password"]; - -foreach( $groups as $i ){ - OC_GROUP::addToGroup( $username, $i ); -} +$name = $_POST["groupname"]; // Return Success story -if( OC_USER::createUser( $username, $password )){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); +if( OC_GROUP::createGroup( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add user" ))); + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add group" ))); } ?> diff --git a/admin/ajax/createuser.php b/admin/ajax/createuser.php index ab99d2a5be..4aa082a25e 100644 --- a/admin/ajax/createuser.php +++ b/admin/ajax/createuser.php @@ -19,12 +19,11 @@ if( isset( $_POST["groups"] )){ $username = $_POST["username"]; $password = $_POST["password"]; -foreach( $groups as $i ){ - OC_GROUP::addToGroup( $username, $i ); -} - // Return Success story if( OC_USER::createUser( $username, $password )){ + foreach( $groups as $i ){ + OC_GROUP::addToGroup( $username, $i ); + } echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); } else{ diff --git a/admin/ajax/removegroup.php b/admin/ajax/removegroup.php new file mode 100644 index 0000000000..c7991ba581 --- /dev/null +++ b/admin/ajax/removegroup.php @@ -0,0 +1,25 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$name = $_POST["groupname"]; + +// Return Success story +if( OC_GROUP::deleteGroup( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete group" ))); +} + +?> diff --git a/admin/ajax/removeuser.php b/admin/ajax/removeuser.php new file mode 100644 index 0000000000..12a27fff58 --- /dev/null +++ b/admin/ajax/removeuser.php @@ -0,0 +1,25 @@ + "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$name = $_POST["username"]; + +// Return Success story +if( OC_USER::deleteUser( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $name ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); +} + +?> diff --git a/admin/js/users.js b/admin/js/users.js index 0713cf8e5d..7cd1ed6f62 100644 --- a/admin/js/users.js +++ b/admin/js/users.js @@ -12,10 +12,15 @@ $(document).ready(function(){ "Create an account": function() { var post = $( "#createuserdata" ).serialize(); $.post( 'ajax/createuser.php', post, function(data){ - var newrow = '' + data.data.username + ''; - newrow = newrow + '' + data.data.groups + ''; - newrow = newrow + 'edit | remove'; - $("#userstable").append( newrow ); + if( data.status == "success" ){ + var newrow = '' + data.data.username + ''; + newrow = newrow + '' + data.data.groups + ''; + newrow = newrow + 'edit | remove'; + $("#userstable").append( newrow ); + } + else{ + alert( "Bug By Jakob (c)" ); + } }); $( this ).dialog( "close" ); }, @@ -61,7 +66,7 @@ $(document).ready(function(){ return false; }); - // Dialog for adding users + // Removing users $( "#removeuser-form" ).dialog({ autoOpen: false, height: 300, @@ -69,6 +74,15 @@ $(document).ready(function(){ modal: true, buttons: { "Remove user": function() { + var post = $( "#removeuserdata" ).serialize(); + $.post( 'ajax/removeuser.php', post, function(data){ + if( data.status == "success" ){ + $( "a[x-uid='"+uid+"']" ).parent().remove(); + } + else{ + alert( "Bug By Jakob (c)" ); + } + }); $( this ).dialog( "close" ); }, Cancel: function() { @@ -76,7 +90,7 @@ $(document).ready(function(){ } }, close: function() { - allFields.val( "" ).removeClass( "ui-state-error" ); + true; } }); @@ -84,10 +98,28 @@ $(document).ready(function(){ .click(function() { uid = $( this ).parent().attr( 'x-uid' ); $("#deleteuserusername").html(uid); + $("#deleteusernamefield").val(uid); $( "#removeuser-form" ).dialog( "open" ); return false; }); + // Add a group + $( "#creategroupbutton" ) + .click(function(){ + var post = $( "#creategroupdata" ).serialize(); + $.post( 'ajax/creategroup.php', post, function(data){ + if( data.status == "success" ){ + var newrow = '' + data.data.groupname + ''; + newrow = newrow + 'remove'; + $("#groupstable").append( newrow ); + } + else{ + alert( "something went wrong! sorry!" ); + } + }); + return false; + }); + // Dialog for adding users $( "#removegroup-form" ).dialog({ autoOpen: false, @@ -96,9 +128,14 @@ $(document).ready(function(){ modal: true, buttons: { "Remove group": function(){ - var post = $( "#deletegroupdata" ).serialize(); - $.post( 'ajax/deletegroup.php', post, function(data){ - $( "a[x-gid='"+gid+"']" ).parent().remove(); + var post = $( "#removegroupdata" ).serialize(); + $.post( 'ajax/removegroup.php', post, function(data){ + if( data.status == "success" ){ + $( "a[x-gid='"+gid+"']" ).parent().remove(); + } + else{ + alert( "Bug By Jakob (c)" ); + } }); $( this ).dialog( "close" ); }, @@ -107,7 +144,7 @@ $(document).ready(function(){ } }, close: function(){ - allFields.val( "" ).removeClass( "ui-state-error" ); + true; } }); diff --git a/admin/templates/users.php b/admin/templates/users.php index ce78ffac77..b2172b0539 100644 --- a/admin/templates/users.php +++ b/admin/templates/users.php @@ -28,7 +28,7 @@ New user

Groups

-
+ @@ -36,6 +36,12 @@ + + + + + + @@ -43,17 +49,10 @@ - - - -
">remove
-Add group - -
@@ -82,13 +81,13 @@
Do you really want to delete user $user? - +
-
+ Do you really want to delete group $group? - +
diff --git a/lib/Group/backend.php b/lib/Group/backend.php index f34c340be8..c3f208157e 100644 --- a/lib/Group/backend.php +++ b/lib/Group/backend.php @@ -35,6 +35,13 @@ abstract class OC_GROUP_BACKEND { */ public static function createGroup($groupName){} + /** + * Try to delete Group + * + * @param string $groupName The name of the group to delete + */ + public static function deleteGroup($groupName){} + /** * Check if a user belongs to a group * diff --git a/lib/Group/database.php b/lib/Group/database.php index e3e6c825b9..aea27a3d6d 100644 --- a/lib/Group/database.php +++ b/lib/Group/database.php @@ -66,6 +66,18 @@ class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { } } + /** + * Try to delete a group + * + * @param string $groupName The name of the group to delete + */ + public static function deleteGroup( $gid ){ + $query = OC_DB::prepare( "DELETE FROM `*PREFIX*groups` WHERE `gid` = ?" ); + $result = $query->execute( array( $gid )); + + return true; + } + /** * Check if a user belongs to a group * diff --git a/lib/User/backend.php b/lib/User/backend.php index 0483d72bf0..29a1932e19 100644 --- a/lib/User/backend.php +++ b/lib/User/backend.php @@ -37,6 +37,12 @@ abstract class OC_USER_BACKEND { */ public static function createUser($username, $password){} + /** + * @brief Delete a new user + * @param $username The username of the user to delete + */ + public static function deleteUser( $username ){} + /** * Try to login a user * diff --git a/lib/User/database.php b/lib/User/database.php index f0b68cf17d..5b68d3ff7c 100644 --- a/lib/User/database.php +++ b/lib/User/database.php @@ -64,6 +64,18 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { } } + /** + * Try to delete a user + * + * @param string $username The username of the user to delete + */ + public static function deleteUser( $uid ){ + $query = OC_DB::prepare( "DELETE FROM `*PREFIX*users` WHERE `uid` = ?" ); + $result = $query->execute( array( $uid )); + + return true; + } + /** * Try to login a user * diff --git a/lib/app.php b/lib/app.php index c9e4d53435..19e6df77f8 100644 --- a/lib/app.php +++ b/lib/app.php @@ -318,7 +318,6 @@ class OC_APP{ * -# unzipping it * -# including appinfo/installer.php * -# executing "oc_app_install()" - * -# renaming appinfo/app.sample.php to appinfo/app.php * * It is the task of oc_app_install to create the tables and do whatever is * needed to get the app working. @@ -346,8 +345,6 @@ class OC_APP{ * - pretend: boolean, if set true the system won't do anything * - noupgrade: boolean, if true the function oc_app_upgrade will be * skipped - * - keepappinfo: boolean. If set true, the folder appinfo will not be - * deleted, appinfo/app.php will not be replaced by a new version * * This function works as follows * -# fetching the file @@ -355,7 +352,6 @@ class OC_APP{ * -# unzipping new file * -# including appinfo/installer.php * -# executing "oc_app_upgrade( $options )" - * -# renaming appinfo/app.sample.php to appinfo/app.php */ public static function upgradeApp( $data = array()){ // TODO: write function diff --git a/lib/filestorage.php b/lib/filestorage.php index e7fb9e9d27..799d07da9d 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -378,6 +378,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } public function fromTmpFile($tmpFile,$path){ +die( "oh nooo!" ); $fileStats = stat($tmpFile); if(rename($tmpFile,$this->datadir.$path)){ touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); @@ -447,7 +448,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } return $return; } - + /** * @brief get the size of folder and it's content * @param string $path file path @@ -462,7 +463,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ return $this->calculateFolderSize($path); } } - + /** * @brief calulate the size of folder and it's content and cache it * @param string $path file path @@ -493,7 +494,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } return $size; } - + /** * @brief clear the folder size cache of folders containing a file * @param string $path diff --git a/lib/group.php b/lib/group.php index 18e34c7277..d8a59a139a 100644 --- a/lib/group.php +++ b/lib/group.php @@ -78,6 +78,24 @@ class OC_GROUP { } } + /** + * Try to create a new group + * + * @param string $groupName The name of the group to create + */ + public static function createGroup($gid) { + return self::$_backend->createGroup($gid); + } + + /** + * Try to delete Group + * + * @param string $groupName The name of the group to delete + */ + public static function deleteGroup($gid) { + return self::$_backend->deleteGroup($gid); + } + /** * Check if a user belongs to a group * diff --git a/lib/user.php b/lib/user.php index d70443b7e6..6cfcc6be48 100644 --- a/lib/user.php +++ b/lib/user.php @@ -95,6 +95,14 @@ class OC_USER { return self::$_backend->createUser( $username, $password ); } + /** + * @brief Delete a new user + * @param $username The username of the user to delete + */ + public static function deleteUser( $username ){ + return self::$_backend->deleteUser( $username ); + } + /** * @brief try to login a user * @param $username The username of the user to log in