summaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-04-17 18:05:49 +0200
committerJakob Sack <kde@jakobsack.de>2011-04-17 18:05:49 +0200
commit79d8aa871a56c18f3857fba86dc5dec14ece51d3 (patch)
tree8be91af2cf24e90b6614f69d5fa5dac53a6c5c2b /admin
parentc070b624a69c0f51ebfb1cd3c3fda01d98bfd91d (diff)
downloadnextcloud-server-79d8aa871a56c18f3857fba86dc5dec14ece51d3.tar.gz
nextcloud-server-79d8aa871a56c18f3857fba86dc5dec14ece51d3.zip
User management works good enough for now. Need to do something else ...
Diffstat (limited to 'admin')
-rw-r--r--admin/ajax/changepassword.php9
-rw-r--r--admin/ajax/removeuser.php22
-rw-r--r--admin/ajax/togglegroups.php17
-rw-r--r--admin/js/users.js174
-rw-r--r--admin/templates/users.php43
5 files changed, 174 insertions, 91 deletions
diff --git a/admin/ajax/changepassword.php b/admin/ajax/changepassword.php
index 12a27fff58d..a8f3af15175 100644
--- a/admin/ajax/changepassword.php
+++ b/admin/ajax/changepassword.php
@@ -12,14 +12,15 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
exit();
}
-$name = $_POST["username"];
+$username = $_POST["username"];
+$password = $_POST["password"];
// Return Success story
-if( OC_USER::deleteUser( $name )){
- echo json_encode( array( "status" => "success", "data" => array( "username" => $name )));
+if( OC_USER::setPassword( $username, $password )){
+ echo json_encode( array( "status" => "success", "data" => array( "username" => $username )));
}
else{
- echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" )));
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to change password" )));
}
?>
diff --git a/admin/ajax/removeuser.php b/admin/ajax/removeuser.php
index 9cf52c128b0..7e587f16058 100644
--- a/admin/ajax/removeuser.php
+++ b/admin/ajax/removeuser.php
@@ -12,30 +12,14 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
exit();
}
-$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( $success ){
- echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", $groups ))));
+if( OC_USER::deleteUser( $username )){
+ echo json_encode( array( "status" => "success", "data" => array( "username" => $username )));
}
else{
- echo json_encode( array( "status" => "error", "data" => array( "message" => "Edit user" )));
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" )));
}
?>
diff --git a/admin/ajax/togglegroups.php b/admin/ajax/togglegroups.php
index 12a27fff58d..cd26dbc1440 100644
--- a/admin/ajax/togglegroups.php
+++ b/admin/ajax/togglegroups.php
@@ -12,11 +12,22 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
exit();
}
-$name = $_POST["username"];
+$success = true;
+
+$username = $_POST["username"];
+$group = $_POST["group"];
+
+// Toggle group
+if( OC_GROUP::inGroup( $username, $group )){
+ OC_GROUP::removeFromGroup( $username, $group );
+}
+else{
+ OC_GROUP::addToGroup( $username, $group );
+}
// 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 )));
}
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 e543e52f1bd..ad1555c95a1 100644
--- a/admin/js/users.js
+++ b/admin/js/users.js
@@ -2,6 +2,35 @@ $(document).ready(function(){
// Vars we need
var uid = "";
var gid = "";
+ var togglepassword = "";
+ var togglegroup = "";
+
+ //#########################################################################
+ // Stuff I don't understand
+ //#########################################################################
+
+ function doToggleGroup( group ){
+ $("#changegroupgid").val(group);
+
+ // Serialize the data
+ var post = $( "#changegroupsform" ).serialize();
+ // Ajax foo
+ $.post( 'ajax/togglegroups.php', post, function(data){
+ if( data.status == "success" ){
+ var groups = [];
+ $("input[x-use='togglegroup']").each( function(index){
+ if( $(this).attr("checked")){
+ groups.push($(this).val());
+ }
+ });
+ $("#changegroups").prev().html( groups.join(", "));
+ }
+ else{
+ alert( "something went wrong! sorry!" );
+ }
+ });
+ return false;
+ }
//#########################################################################
// Functions for editing the dom after user manipulation
@@ -10,9 +39,9 @@ $(document).ready(function(){
// 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>';
+ var newrow = '<tr x-uid="'+username+'"><td x-use="username"><span x-use="usernamespan">'+username+'</span></td>';
+ newrow = newrow+'<td x-use="usergroups">'+groups+'</td>';
+ newrow = newrow+'<td><a href="" class="edituserbutton">edit</a> | <a class="removeuserbutton" href="">remove</a></td></tr>';
$("#usertable").append( newrow );
// Clear forms
@@ -20,21 +49,12 @@ $(document).ready(function(){
$("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();
+ $( "tr[x-uid='"+username+"']" ).remove();
}
function groupCreated( groupname ){
- var newrow = '<tr><td x-gid="'+groupname+'">' + groupname + '</td>';
+ var newrow = '<tr x-gid="'+groupname+'"><td>' + groupname + '</td>';
newrow = newrow + '<td><a class="removegroupbutton" href="">remove</a></td></tr>';
$("#grouptable").append( newrow );
@@ -42,14 +62,15 @@ $(document).ready(function(){
$("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>';
+ var createuser = '<input x-gid="'+groupname+'" type="checkbox" name="groups[]" value="'+groupname+'" /><span x-gid="'+groupname+'">'+groupname+'<br /></span>';
$("#createusergroups").append( createuser );
- $("#editusergroups").append( createuser );
+ var changeuser = '<input x-use="togglegroup" x-gid="'+groupname+'" type="checkbox" name="groups[]" value="'+groupname+'" /><span x-use="togglegroup" x-gid="'+groupname+'">'+groupname+'<br /></span>';
+ $("#changegroupsform").append( changeuser );
}
function groupRemoved( groupname ){
// Delete the options
- $( "td[x-gid='"+groupname+"']" ).parent().remove();
+ $( "tr[x-gid='"+groupname+"']" ).remove();
$( "span[x-gid='"+groupname+"']" ).remove();
$( "input[x-gid='"+groupname+"']" ).remove();
@@ -71,6 +92,95 @@ $(document).ready(function(){
}
//#########################################################################
+ // Editing the users properties by clicking the cell
+ //#########################################################################
+
+ // Password (clicking on user name)
+ $("span[x-use='usernamespan']").live( "click", function(){
+ if( togglepassword == "" || $(this).parent().parent().attr("x-uid") != togglepassword ){
+ togglepassword = $(this).parent().parent().attr("x-uid");
+ // Set the username!
+ $("#changepassworduid").val(togglepassword);
+ $("#changepasswordpwd").val("");
+ $(this).parent().append( $('#changepassword') );
+ $('#changepassword').show();
+ }
+ else{
+ $('#changepassword').hide();
+ togglepassword = "";
+ }
+ });
+
+ $("#changepasswordbutton").click( function(){
+ // Serialize the data
+ var post = $( "#changepasswordform" ).serialize();
+ // Ajax foo
+ $.post( 'ajax/changepassword.php', post, function(data){
+ if( data.status == "success" ){
+ togglepassword = "";
+ $('#changepassword').hide();
+ }
+ else{
+ alert( "something went wrong! sorry!" );
+ }
+ });
+ return false;
+ });
+
+ // Groups
+ $("span[x-use='usergroupsspan']").live( "click", function(){
+ if( togglegroup == "" || $(this).parent().parent().attr("x-uid") != togglegroup){
+ togglegroup = $(this).parent().parent().attr("x-uid");
+ var groups = $(this).text();
+ groups = groups.split(", ");
+ $("input[x-use='togglegroup']").each( function(index){
+ var check = false;
+ // Group checked?
+ for( var i = 0; i < groups.length; i++ ){
+ if( $(this).val() == groups[i] ){
+ check = true;
+ }
+ }
+
+ // Check/uncheck
+ if( check ){
+ $(this).attr("checked","checked");
+ }
+ else{
+ $(this).removeAttr("checked");
+ }
+ });
+ $("#changegroupuid").val(togglegroup);
+ $(this).parent().append( $('#changegroups') );
+ $('#changegroups').show();
+ }
+ else{
+ var groups = [];
+ $("input[x-use='togglegroup']").each( function(index){
+ if( $(this).attr("checked")){
+ groups.push($(this).val());
+ }
+ });
+ $(this).html( groups.join(", "));
+ $('#changegroups').hide();
+ togglegroup = "";
+ }
+ });
+
+ $("span[x-use='togglegroup']").live( "click", function(){
+ if( $(this).prev().attr("checked")){
+ $(this).prev().removeAttr("checked")
+ }
+ else{
+ $(this).prev().attr("checked","checked")
+ }
+ doToggleGroup( $(this).attr("x-gid"));
+ });
+
+ $("input[x-use='togglegroup']").live( "click", function(){
+ doToggleGroup( $(this).attr("x-gid"));
+ });
+ //#########################################################################
// Clicking on buttons
//#########################################################################
@@ -100,15 +210,8 @@ $(document).ready(function(){
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' );
+ uid = $( this ).parent().parent().attr( 'x-uid' );
$("#deleteuserusername").html(uid);
$("#deleteusernamefield").val(uid);
$("#removeuserform").dialog( "open" );
@@ -132,7 +235,7 @@ $(document).ready(function(){
});
$( ".removegroupbutton" ).live( 'click', function(){
- gid = $( this ).parent().attr( 'x-gid' );
+ gid = $( this ).parent().parent().attr( 'x-gid' );
$("#removegroupgroupname").html(gid);
$("#removegroupnamefield").val(gid);
$("#removegroupform").dialog( "open" );
@@ -143,25 +246,6 @@ $(document).ready(function(){
// Dialogs
//#########################################################################
- // Edit user dialog
- $( "#edituserform" ).dialog({
- autoOpen: false,
- height: 500,
- width: 500,
- modal: true,
- buttons: {
- "Edit user": function() {
- $( this ).dialog( "close" );
- },
- Cancel: function() {
- $( this ).dialog( "close" );
- }
- },
- close: function() {
- true;
- }
- });
-
// Removing users
$( "#removeuserform" ).dialog({
autoOpen: false,
diff --git a/admin/templates/users.php b/admin/templates/users.php
index 081ba189e9b..509fca64103 100644
--- a/admin/templates/users.php
+++ b/admin/templates/users.php
@@ -34,10 +34,10 @@
</tfoot>
<tbody>
<?php foreach($_["users"] as $user): ?>
- <tr>
- <td><?php echo $user["name"]; ?></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 x-uid="<?php echo $user["name"] ?>">
+ <td x-use="username"><span x-use="usernamespan"><?php echo $user["name"]; ?></span></td>
+ <td x-use="usergroups"><span x-use="usergroupsspan"><?php echo $user["groups"]; ?></span></td>
+ <td><a class="removeuserbutton" href="">remove</a></td>
</tr>
<?php endforeach; ?>
</tbody>
@@ -61,9 +61,9 @@
</tfoot>
<tbody>
<?php foreach($_["groups"] as $group): ?>
- <tr>
+ <tr x-gid="<?php echo $group["name"]; ?>">
<td><?php echo $group["name"] ?></td>
- <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroupbutton" href="">remove</a></td>
+ <td><a class="removegroupbutton" href="">remove</a></td>
</tr>
<?php endforeach; ?>
</tbody>
@@ -71,20 +71,23 @@
-<div id="edituserform" title="Force new password">
- <form id="edituserdata">
- <span id="edituserusername">$user</span><br>
- <fieldset>
- New password:
- <input type="password" name="password" value="" />
- </fieldset>
- <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>
+<div id="changegroups" style="display:none">
+ <form id="changegroupsform">
+ <input id="changegroupuid" type="hidden" name="username" value="" />
+ <input id="changegroupgid" type="hidden" name="group" value="" />
+ <?php foreach($_["groups"] as $i): ?>
+ <input x-use="togglegroup" x-gid="<? echo $i["name"]; ?>" type="checkbox" name="groups[]" value="<? echo $i["name"]; ?>" />
+ <span x-use="togglegroup" x-gid="<? echo $i["name"]; ?>"><? echo $i["name"]; ?><br></span>
+ <?php endforeach; ?>
+ </form>
+</div>
+
+<div id="changepassword" style="display:none">
+ <form id="changepasswordform">
+ <input id="changepassworduid" type="hidden" name="username" value="" />
+ Force new password:
+ <input id="changepasswordpwd" type="password" name="password" value="" />
+ <button id="changepasswordbutton">Set</button>
</form>
</div>