Skip to content
Snippets Groups Projects
Commit da5d3882 authored by Jakob Sack's avatar Jakob Sack
Browse files

Advanced user management

parent 9947428d
No related branches found
No related tags found
No related merge requests found
<?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" )));
}
?>
<?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" )));
}
?>
$(document).ready(function(){ $(document).ready(function(){
// Vars we need
var uid = "";
var gid = "";
// Dialog for adding users // Dialog for adding users
$( "#adduser-form" ).dialog({ $( "#adduser-form" ).dialog({
autoOpen: false, autoOpen: false,
...@@ -7,6 +10,13 @@ $(document).ready(function(){ ...@@ -7,6 +10,13 @@ $(document).ready(function(){
modal: true, modal: true,
buttons: { buttons: {
"Create an account": function() { "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" ); $( this ).dialog( "close" );
}, },
Cancel: function() { Cancel: function() {
...@@ -14,7 +24,7 @@ $(document).ready(function(){ ...@@ -14,7 +24,7 @@ $(document).ready(function(){
} }
}, },
close: function() { close: function() {
allFields.val( "" ).removeClass( "ui-state-error" ); true;
} }
}); });
...@@ -39,13 +49,15 @@ $(document).ready(function(){ ...@@ -39,13 +49,15 @@ $(document).ready(function(){
} }
}, },
close: function() { close: function() {
allFields.val( "" ).removeClass( "ui-state-error" ); true;
} }
}); });
$( ".edituser-button" ) $( ".edituser-button" )
.click(function() { .click(function(){
$( "#edituser-form" ).dialog( "open" ); uid = $( this ).parent().attr( 'x-uid' );
$("#edituserusername").html(uid);
$("#edituser-form").dialog("open");
return false; return false;
}); });
...@@ -70,6 +82,8 @@ $(document).ready(function(){ ...@@ -70,6 +82,8 @@ $(document).ready(function(){
$( ".removeuser-button" ) $( ".removeuser-button" )
.click(function() { .click(function() {
uid = $( this ).parent().attr( 'x-uid' );
$("#deleteuserusername").html(uid);
$( "#removeuser-form" ).dialog( "open" ); $( "#removeuser-form" ).dialog( "open" );
return false; return false;
}); });
...@@ -81,21 +95,28 @@ $(document).ready(function(){ ...@@ -81,21 +95,28 @@ $(document).ready(function(){
width: 350, width: 350,
modal: true, modal: true,
buttons: { 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" ); $( this ).dialog( "close" );
}, },
Cancel: function() { Cancel: function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} }
}, },
close: function() { close: function(){
allFields.val( "" ).removeClass( "ui-state-error" ); allFields.val( "" ).removeClass( "ui-state-error" );
} }
}); });
$( ".removegroup-button" ) $( ".removegroup-button" )
.click(function() { .click(function(){
$( "#removegroup-form" ).dialog( "open" ); gid = $( this ).parent().attr( 'x-gid' );
$("#deletegroupgroupname").html(gid);
$("#deletegroupnamefield").val(gid);
$("#removegroup-form").dialog( "open" );
return false; return false;
}); });
} ); } );
...@@ -28,15 +28,7 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' ...@@ -28,15 +28,7 @@ if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin'
exit(); exit();
} }
$adminpages = array(); $tmpl = new OC_TEMPLATE( "admin", "system", "admin" );
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->printPage(); $tmpl->printPage();
?> ?>
......
...@@ -6,20 +6,20 @@ ...@@ -6,20 +6,20 @@
<h1>Administration</h1> <h1>Administration</h1>
<h2>Users</h2> <h2>Users</h2>
<table> <table id="userstable">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Groups</th> <th>Groups</th>
<th></th> <th></th>
</tr> </tr>
<thead> </thead>
<tbody> <tbody>
<?php foreach($_["users"] as $user): ?> <?php foreach($_["users"] as $user): ?>
<tr> <tr>
<td><?php echo $user["name"]; ?></td> <td><?php echo $user["name"]; ?></td>
<td><?php echo $user["groups"]; ?></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> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
...@@ -29,18 +29,18 @@ ...@@ -29,18 +29,18 @@
<h2>Groups</h2> <h2>Groups</h2>
<form> <form>
<table> <table id="groupstable">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th></th> <th></th>
</tr> </tr>
<thead> </thead>
<tbody> <tbody>
<?php foreach($_["groups"] as $group): ?> <?php foreach($_["groups"] as $group): ?>
<tr> <tr>
<td><?php echo $group["name"] ?></td> <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> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr> <tr>
...@@ -55,25 +55,40 @@ ...@@ -55,25 +55,40 @@
<div id="adduser-form" title="Add user"> <div id="adduser-form" title="Add user">
<form> <form id="createuserdata">
<fieldset>
User name<br> User name<br>
<input type="text" name="name" /><br> <input type="text" name="username" /><br>
Password<br> Password<br>
<input type="password" name="password" /> <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> </form>
</div> </div>
<div id="edituser-form" title="Force new password"> <div id="edituser-form" title="Force new password">
<form> <form id="edituserdata">
New password for $user<br> New password for <span id="edituserusername">$user</span><br>
<input type="password" name="password" /> <input type="password" name="password" />
<input type="hidden" name="username" value="">
</form> </form>
</div> </div>
<div id="removeuser-form" title="Remove user"> <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>
<div id="removegroup-form" title="Remove Group"> <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> </div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment