diff options
author | Jakob Sack <kde@jakobsack.de> | 2011-04-17 13:15:55 +0200 |
---|---|---|
committer | Jakob Sack <kde@jakobsack.de> | 2011-04-17 13:15:55 +0200 |
commit | afa2c4a2c31c6cb293981cdb25f264fe96fb3b98 (patch) | |
tree | 44318f8539e1d9ab43870effee60826528d0a410 /admin | |
parent | 58cb46c4e85ff4af41d91522e8fcba89e01fed81 (diff) | |
download | nextcloud-server-afa2c4a2c31c6cb293981cdb25f264fe96fb3b98.tar.gz nextcloud-server-afa2c4a2c31c6cb293981cdb25f264fe96fb3b98.zip |
User manager still not perfect but the aim is reachable!
Diffstat (limited to 'admin')
-rw-r--r-- | admin/ajax/changepassword.php | 25 | ||||
-rw-r--r-- | admin/ajax/removeuser.php | 24 | ||||
-rw-r--r-- | admin/ajax/togglegroups.php | 25 | ||||
-rw-r--r-- | admin/js/users.js | 228 | ||||
-rw-r--r-- | admin/templates/users.php | 118 | ||||
-rw-r--r-- | admin/users.php | 2 |
6 files changed, 281 insertions, 141 deletions
diff --git a/admin/ajax/changepassword.php b/admin/ajax/changepassword.php new file mode 100644 index 00000000000..12a27fff58d --- /dev/null +++ b/admin/ajax/changepassword.php @@ -0,0 +1,25 @@ +<?php + +// Init owncloud +require_once('../../lib/base.php'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ + echo json_encode( array( "status" => "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/ajax/removeuser.php b/admin/ajax/removeuser.php index 12a27fff58d..9cf52c128b0 100644 --- a/admin/ajax/removeuser.php +++ b/admin/ajax/removeuser.php @@ -12,14 +12,30 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' exit(); } -$name = $_POST["username"]; +$groups = array(); +$username = $_POST["username"]; +$password = $_POST["password"]; +$groups = $_POST["groups"]; + +$success = true; +if( $password ){ + $success = $success && OC_USER::setPassword( $username, $password ); +} + +// update groups (delete old ones, add new ones) +foreach( OC_GROUP::getUserGroups( $username ) as $i ){ + OC_GROUP::removeFromGroup( $username, $i ); +} +foreach( $groups as $i ){ + OC_GROUP::addToGroup( $username, $i ); +} // Return Success story -if( OC_USER::deleteUser( $name )){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $name ))); +if( $success ){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups )))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); + echo json_encode( array( "status" => "error", "data" => array( "message" => "Edit user" ))); } ?> diff --git a/admin/ajax/togglegroups.php b/admin/ajax/togglegroups.php new file mode 100644 index 00000000000..12a27fff58d --- /dev/null +++ b/admin/ajax/togglegroups.php @@ -0,0 +1,25 @@ +<?php + +// Init owncloud +require_once('../../lib/base.php'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ + echo json_encode( array( "status" => "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 7cd1ed6f624..e543e52f1bd 100644 --- a/admin/js/users.js +++ b/admin/js/users.js @@ -2,51 +2,155 @@ $(document).ready(function(){ // Vars we need var uid = ""; var gid = ""; - // Dialog for adding users - $( "#adduser-form" ).dialog({ - autoOpen: false, - height: 300, - width: 350, - modal: true, - buttons: { - "Create an account": function() { - var post = $( "#createuserdata" ).serialize(); - $.post( 'ajax/createuser.php', post, function(data){ - if( data.status == "success" ){ - var newrow = '<tr><td>' + data.data.username + '</td>'; - newrow = newrow + '<td>' + data.data.groups + '</td>'; - newrow = newrow + '<td><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td></tr>'; - $("#userstable").append( newrow ); - } - else{ - alert( "Bug By Jakob (c)" ); - } - }); - $( this ).dialog( "close" ); - }, - Cancel: function() { - $( this ).dialog( "close" ); + + //######################################################################### + // Functions for editing the dom after user manipulation + //######################################################################### + + // Manipulating the page after crteating a user + function userCreated( username, groups ){ + // Add user to table + var newrow = '<tr><td>'+username+'</td>'; + newrow = newrow+'<td>'+groups+'</td>'; + newrow = newrow+'<td x-uid="'+username+'"><a href="" class="edituserbutton">edit</a> | <a class="removeuserbutton" href="">remove</a></td></tr>'; + $("#usertable").append( newrow ); + + // Clear forms + $("input[x-use='createuserfield']").val( "" ); + $("input[x-use='createusercheckbox']").attr( "checked", false ); + } + + // Manipulating the page after crteating a user + function userEdited( username, groups ){ + // Edit table + var newrow = '<tr><td>'+username+'</td>'; + newrow = newrow+'<td>'+groups+'</td>'; + newrow = newrow+'<td x-uid="'+username+'"><a href="" class="edituserbutton">edit</a> | <a class="removeuserbutton" href="">remove</a></td></tr>'; + $("td[x-uid='"+username+"']").replace( newrow ); + } + + function userRemoved( username ){ + $( "td[x-uid='"+username+"']" ).parent().remove(); + } + + function groupCreated( groupname ){ + var newrow = '<tr><td x-gid="'+groupname+'">' + groupname + '</td>'; + newrow = newrow + '<td><a class="removegroupbutton" href="">remove</a></td></tr>'; + $("#grouptable").append( newrow ); + + // Delete form content + $("input[x-use='creategroupfield']").val( "" ); + + // Add group option to Create User and Edit User + createuser = '<input x-gid="'+groupname+'" type="checkbox" name="groups[]" value="'+groupname+'" /><span x-gid="'+groupname+'">'+groupname+'<br /></span>'; + $("#createusergroups").append( createuser ); + $("#editusergroups").append( createuser ); + } + + function groupRemoved( groupname ){ + // Delete the options + $( "td[x-gid='"+groupname+"']" ).parent().remove(); + $( "span[x-gid='"+groupname+"']" ).remove(); + $( "input[x-gid='"+groupname+"']" ).remove(); + + // remove it from user list + $( "td[x-use='usergroups']" ).each(function(index){ + var content = $(this).text(); + var list = content.split( ", " ); + var newlist = []; + for( var i = 0; i < list.length; i++ ){ + var temp = list[i]; + if( temp != groupname ){ + newlist.push( temp ); + } } - }, - close: function() { - true; - } - }); + var newstring = newlist.join( ", " ); + $(this).html( newstring ) + }); + + } - $( "#adduser-button" ) - .click(function() { - $( "#adduser-form" ).dialog( "open" ); + //######################################################################### + // Clicking on buttons + //######################################################################### + + // Show the create user form + $( "#createuseroptionbutton" ) + .click(function(){ + $( "#createuserform" ).toggle(); return false; }); - // Dialog for adding users - $( "#edituser-form" ).dialog({ + // Create a new user + $( "#createuserbutton" ) + .click(function(){ + // Create the post data + var post = $( "#createuserdata" ).serialize(); + + // Ajax call + $.post( 'ajax/createuser.php', post, function(data){ + // If it says "success" then we are happy + if( data.status == "success" ){ + userCreated( data.data.username, data.data.groups ); + } + else{ + alert( "Bug By Jakob (c)" ); + } + }); + return false; + }); + + $( ".edituserbutton" ).live( 'click', function(){ + uid = $( this ).parent().attr( 'x-uid' ); + $("#edituserusername").html(uid); + $("#edituserform").dialog("open"); + return false; + }); + + $( ".removeuserbutton" ).live( 'click', function() { + uid = $( this ).parent().attr( 'x-uid' ); + $("#deleteuserusername").html(uid); + $("#deleteusernamefield").val(uid); + $("#removeuserform").dialog( "open" ); + return false; + }); + + $( "#creategroupbutton" ) + .click(function(){ + // Serialize the data + var post = $( "#creategroupdata" ).serialize(); + // Ajax foo + $.post( 'ajax/creategroup.php', post, function(data){ + if( data.status == "success" ){ + groupCreated( data.data.groupname ); + } + else{ + alert( "something went wrong! sorry!" ); + } + }); + return false; + }); + + $( ".removegroupbutton" ).live( 'click', function(){ + gid = $( this ).parent().attr( 'x-gid' ); + $("#removegroupgroupname").html(gid); + $("#removegroupnamefield").val(gid); + $("#removegroupform").dialog( "open" ); + return false; + }); + + //######################################################################### + // Dialogs + //######################################################################### + + // Edit user dialog + $( "#edituserform" ).dialog({ autoOpen: false, - height: 300, - width: 350, + height: 500, + width: 500, modal: true, buttons: { - "Edit password": function() { + "Edit user": function() { $( this ).dialog( "close" ); }, Cancel: function() { @@ -58,16 +162,8 @@ $(document).ready(function(){ } }); - $( ".edituser-button" ) - .click(function(){ - uid = $( this ).parent().attr( 'x-uid' ); - $("#edituserusername").html(uid); - $("#edituser-form").dialog("open"); - return false; - }); - // Removing users - $( "#removeuser-form" ).dialog({ + $( "#removeuserform" ).dialog({ autoOpen: false, height: 300, width: 350, @@ -77,7 +173,7 @@ $(document).ready(function(){ var post = $( "#removeuserdata" ).serialize(); $.post( 'ajax/removeuser.php', post, function(data){ if( data.status == "success" ){ - $( "a[x-uid='"+uid+"']" ).parent().remove(); + userRemoved( uid ); } else{ alert( "Bug By Jakob (c)" ); @@ -94,34 +190,9 @@ $(document).ready(function(){ } }); - $( ".removeuser-button" ) - .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 = '<tr><td>' + data.data.groupname + '</td>'; - newrow = newrow + '<td><a class="removegroup-button" href="">remove</a></td></tr>'; - $("#groupstable").append( newrow ); - } - else{ - alert( "something went wrong! sorry!" ); - } - }); - return false; - }); // Dialog for adding users - $( "#removegroup-form" ).dialog({ + $( "#removegroupform" ).dialog({ autoOpen: false, height: 300, width: 350, @@ -131,7 +202,7 @@ $(document).ready(function(){ var post = $( "#removegroupdata" ).serialize(); $.post( 'ajax/removegroup.php', post, function(data){ if( data.status == "success" ){ - $( "a[x-gid='"+gid+"']" ).parent().remove(); + groupRemoved( gid ); } else{ alert( "Bug By Jakob (c)" ); @@ -148,12 +219,5 @@ $(document).ready(function(){ } }); - $( ".removegroup-button" ) - .click(function(){ - gid = $( this ).parent().attr( 'x-gid' ); - $("#deletegroupgroupname").html(gid); - $("#deletegroupnamefield").val(gid); - $("#removegroup-form").dialog( "open" ); - return false; - }); } ); + diff --git a/admin/templates/users.php b/admin/templates/users.php index b2172b05399..081ba189e9b 100644 --- a/admin/templates/users.php +++ b/admin/templates/users.php @@ -1,12 +1,6 @@ -<?php -/* - * Template for admin pages - */ -?> -<h1>Administration</h1> <h2>Users</h2> -<table id="userstable"> +<table id="usertable"> <thead> <tr> <th>Name</th> @@ -14,80 +8,96 @@ <th></th> </tr> </thead> + <tfoot> + <tr id="createuseroption"> + <td><button id="createuseroptionbutton">Add user</button></td> + <td> </td> + <td> </td> + </tr> + <form id="createuserdata"> + <tr id="createuserform" style="display:none;"> + <td> + Name <input x-use="createuserfield" type="text" name="username" /><br> + Password <input x-use="createuserfield" type="password" name="password" /> + </td> + <td id="createusergroups"> + <?php foreach($_["groups"] as $i): ?> + <input x-use="createusercheckbox" x-gid="<? echo $i["name"]; ?>" type="checkbox" name="groups[]" value="<? echo $i["name"]; ?>" /> + <span x-gid="<? echo $i["name"]; ?>"><? echo $i["name"]; ?><br></span> + <?php endforeach; ?> + </td> + <td> + <button id="createuserbutton">Create user</button> + </td> + </tr> + </form> + </tfoot> <tbody> <?php foreach($_["users"] as $user): ?> <tr> <td><?php echo $user["name"]; ?></td> - <td><?php echo $user["groups"]; ?></td> - <td x-uid="<?php echo $user["name"] ?>"><a href="" class="edituser-button">edit</a> | <a class="removeuser-button" href="">remove</a></td> + <td x-use="usergroups"><?php echo $user["groups"]; ?></td> + <td x-uid="<?php echo $user["name"] ?>"><a href="" class="edituserbutton">edit</a> | <a class="removeuserbutton" href="">remove</a></td> </tr> <?php endforeach; ?> </tbody> </table> -<a id="adduser-button" href="">New user</a> - <h2>Groups</h2> -<form id="creategroupdata"> - <table id="groupstable"> - <thead> +<table id="grouptable"> + <thead> + <tr> + <th>Name</th> + <th></th> + </tr> + </thead> + <tfoot> + <form id="creategroupdata"> <tr> - <th>Name</th> - <th></th> + <td><input x-use="creategroupfield" type="text" name="groupname" /></td> + <td><button id="creategroupbutton">Create group</button></td> </tr> - </thead> - <tfoot> + </form> + </tfoot> + <tbody> + <?php foreach($_["groups"] as $group): ?> <tr> - <td><input type="text" name="groupname" id="creategroupname" /></td> - <td><button id="creategroupbutton">Create group</button></td> + <td><?php echo $group["name"] ?></td> + <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroupbutton" href="">remove</a></td> </tr> - </tfoot> - <tbody> - <?php foreach($_["groups"] as $group): ?> - <tr> - <td><?php echo $group["name"] ?></td> - <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroup-button" href="">remove</a></td> - </tr> - <?php endforeach; ?> - </tbody> - </table> -</form> + <?php endforeach; ?> + </tbody> +</table> -<div id="adduser-form" title="Add user"> - <form id="createuserdata"> + + +<div id="edituserform" title="Force new password"> + <form id="edituserdata"> + <span id="edituserusername">$user</span><br> <fieldset> - User name<br> - <input type="text" name="username" /><br> - Password<br> - <input type="password" name="password" /> + New password: + <input type="password" name="password" value="" /> </fieldset> - <fieldset id="usergroups"> - groups<br> - <?php foreach($_["groups"] as $i): ?> - <input type="checkbox" name="groups[]" value="<? echo $i["name"]; ?>" /><? echo $i["name"]; ?><br> - <?php endforeach; ?> + <input type="hidden" name="username" value="" /> + <fieldset id="editusergroups"> + <?php foreach($_["groups"] as $i): ?> + <input x-gid="<? echo $i["name"]; ?>" type="checkbox" name="groups[]" value="<? echo $i["name"]; ?>" /> + <span x-gid="<? echo $i["name"]; ?>"><? echo $i["name"]; ?><br></span> + <?php endforeach; ?> </fieldset> </form> </div> -<div id="edituser-form" title="Force new password"> - <form id="edituserdata"> - New password for <span id="edituserusername">$user</span><br> - <input type="password" name="password" /> - <input type="hidden" name="username" value=""> - </form> -</div> - -<div id="removeuser-form" title="Remove user"> +<div id="removeuserform" title="Remove user"> <form id="removeuserdata"> Do you really want to delete user <span id="deleteuserusername">$user</span>? <input id="deleteusernamefield" type="hidden" name="username" value=""> </form> </div> -<div id="removegroup-form" title="Remove Group"> +<div id="removegroupform" title="Remove Group"> <form id="removegroupdata"> - Do you really want to delete group <span id="deletegroupgroupname">$group</span>? - <input id="deletegroupnamefield" type="hidden" name="groupname" value=""> + Do you really want to delete group <span id="removegroupgroupname">$group</span>? + <input id="removegroupnamefield" type="hidden" name="groupname" value=""> </form> </div> diff --git a/admin/users.php b/admin/users.php index 312bfba2c52..9529ea74977 100644 --- a/admin/users.php +++ b/admin/users.php @@ -40,7 +40,7 @@ foreach( OC_USER::getUsers() as $i ){ foreach( OC_GROUP::getUserGroups( $i ) as $userGroup ){ $ingroups[] = $userGroup; } - $users[] = array( "name" => $i, "groups" => join( ",", $ingroups )); + $users[] = array( "name" => $i, "groups" => join( ", ", $ingroups )); } foreach( OC_GROUP::getGroups() as $i ){ |