]> source.dussan.org Git - nextcloud-server.git/commitdiff
Advanced user management
authorJakob Sack <kde@jakobsack.de>
Sat, 16 Apr 2011 21:26:55 +0000 (23:26 +0200)
committerJakob Sack <kde@jakobsack.de>
Sat, 16 Apr 2011 21:26:55 +0000 (23:26 +0200)
admin/ajax/creategroup.php [new file with mode: 0644]
admin/ajax/createuser.php [new file with mode: 0644]
admin/js/users.js
admin/system.php
admin/templates/users.php

diff --git a/admin/ajax/creategroup.php b/admin/ajax/creategroup.php
new file mode 100644 (file)
index 0000000..ab99d2a
--- /dev/null
@@ -0,0 +1,34 @@
+<?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();
+}
+
+$groups = array();
+if( isset( $_POST["groups"] )){
+       $groups = $_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 )){
+       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 add user" )));
+}
+
+?>
diff --git a/admin/ajax/createuser.php b/admin/ajax/createuser.php
new file mode 100644 (file)
index 0000000..ab99d2a
--- /dev/null
@@ -0,0 +1,34 @@
+<?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();
+}
+
+$groups = array();
+if( isset( $_POST["groups"] )){
+       $groups = $_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 )){
+       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 add user" )));
+}
+
+?>
index 6d59a2efb7c7c4cc92aea2d5116fe26c294493a5..0713cf8e5dcb8bc12ef149fdd980a347753734b9 100644 (file)
@@ -1,4 +1,7 @@
 $(document).ready(function(){
+       // Vars we need
+       var uid = "";
+       var gid = "";
        // Dialog for adding users
        $( "#adduser-form" ).dialog({
                autoOpen: false,
@@ -7,6 +10,13 @@ $(document).ready(function(){
                modal: true,
                buttons: {
                        "Create an account": function() {
+                               var post = $( "#createuserdata" ).serialize();
+                               $.post( 'ajax/createuser.php', post, function(data){
+                                       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  );
+                               });
                                $( this ).dialog( "close" );
                        },
                        Cancel: function() {
@@ -14,7 +24,7 @@ $(document).ready(function(){
                        }
                },
                close: function() {
-                       allFields.val( "" ).removeClass( "ui-state-error" );
+                       true;
                }
        });
 
@@ -39,13 +49,15 @@ $(document).ready(function(){
                        }
                },
                close: function() {
-                       allFields.val( "" ).removeClass( "ui-state-error" );
+                       true;
                }
        });
 
        $( ".edituser-button" )
-               .click(function() {
-                       $( "#edituser-form" ).dialog( "open" );
+               .click(function(){
+                       uid = $( this ).parent().attr( 'x-uid' );
+                       $("#edituserusername").html(uid);
+                       $("#edituser-form").dialog("open");
                        return false;
                });
 
@@ -70,6 +82,8 @@ $(document).ready(function(){
 
        $( ".removeuser-button" )
                .click(function() {
+                       uid = $( this ).parent().attr( 'x-uid' );
+                       $("#deleteuserusername").html(uid);
                        $( "#removeuser-form" ).dialog( "open" );
                        return false;
                });
@@ -81,21 +95,28 @@ $(document).ready(function(){
                width: 350,
                modal: true,
                buttons: {
-                       "Remove group": function() {
+                       "Remove group": function(){
+                               var post = $( "#deletegroupdata" ).serialize();
+                               $.post( 'ajax/deletegroup.php', post, function(data){
+                                       $( "a[x-gid='"+gid+"']" ).parent().remove();
+                               });
                                $( this ).dialog( "close" );
                        },
                        Cancel: function() {
                                $( this ).dialog( "close" );
                        }
                },
-               close: function() {
+               close: function(){
                        allFields.val( "" ).removeClass( "ui-state-error" );
                }
        });
 
        $( ".removegroup-button" )
-               .click(function() {
-                       $( "#removegroup-form" ).dialog( "open" );
+               .click(function(){
+                       gid = $( this ).parent().attr( 'x-gid' );
+                       $("#deletegroupgroupname").html(gid);
+                       $("#deletegroupnamefield").val(gid);
+                       $("#removegroup-form").dialog( "open" );
                        return false;
                });
 } );
index 8abef287098ab8b962af3fc83f72ab76a7a5209a..de62b133f85b33a457e627b582780e498b64d9e1 100644 (file)
@@ -28,15 +28,7 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
        exit();
 }
 
-$adminpages = array();
-
-foreach( OC_APP::getAdminPages() as $i ){
-       // Do some more work here soon
-       $adminpages[] = $i;
-}
-
-$tmpl = new OC_TEMPLATE( "admin", "index", "admin" );
-$tmpl->assign( "adminpages", $adminpages );
+$tmpl = new OC_TEMPLATE( "admin", "system", "admin" );
 $tmpl->printPage();
 
 ?>
index 88edc01aef28996fabd4d1d4feabb0a3b53ea98b..ce78ffac775d174a710215cf262c72babf73f135 100644 (file)
@@ -6,20 +6,20 @@
 <h1>Administration</h1>
 <h2>Users</h2>
 
-<table>
+<table id="userstable">
        <thead>
                <tr>
                        <th>Name</th>
                        <th>Groups</th>
                        <th></th>
                </tr>
-       <thead>
+       </thead>
        <tbody>
                <?php foreach($_["users"] as $user): ?>
                        <tr>
                                <td><?php echo $user["name"]; ?></td>
                                <td><?php echo $user["groups"]; ?></td>
-                               <td><a href="" class="edituser-button">edit</a> | <a  class="removeuser-button" href="">remove</a></td>
+                               <td x-uid="<?php echo $user["name"] ?>"><a href="" class="edituser-button">edit</a> | <a  class="removeuser-button" href="">remove</a></td>
                        </tr>
                <?php endforeach; ?>
        </tbody>
 
 <h2>Groups</h2>
 <form>
-       <table>
+       <table id="groupstable">
                <thead>
                        <tr>
                                <th>Name</th>
                                <th></th>
                        </tr>
-               <thead>
+               </thead>
                <tbody>
                        <?php foreach($_["groups"] as $group): ?>
                                <tr>
                                        <td><?php echo $group["name"] ?></td>
-                                       <td><a  class="removegroup-button" href="">remove</a></td>
+                                       <td x-gid="<?php echo $group["name"]; ?>"><a class="removegroup-button" href="">remove</a></td>
                                </tr>
                        <?php endforeach; ?>
                        <tr>
 
 
 <div id="adduser-form" title="Add user">
-       <form>
+       <form id="createuserdata">
+               <fieldset>
                User name<br>
-               <input type="text" name="name" /><br>
+               <input type="text" name="username" /><br>
                Password<br>
                <input type="password" name="password" />
+               </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; ?>
+               </fieldset>
        </form>
 </div>
 
 <div id="edituser-form" title="Force new password">
-       <form>
-               New password for $user<br>
+       <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">
-       Do you really want to delete user $user?
+       <form id="removeuserdata">
+               Do you really want to delete user <span id="deleteuserusername">$user</span>?
+               <input type="hidden" name="username" value="">
+       </form>
 </div>
 
 <div id="removegroup-form" title="Remove Group">
-       Do you really want to delete group $group?
+       <form id="removeuserdata">
+               Do you really want to delete group <span id="deletegroupgroupname">$group</span>?
+               <input id="deletegroupnamefield" type="hidden" name="username" value="">
+       </form>
 </div>