Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring

This commit is contained in:
Jan-Christoph Borchardt 2011-04-17 13:17:56 +02:00
commit 793c507af2
6 changed files with 293 additions and 153 deletions

View File

@ -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" )));
}
?>

View File

@ -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" )));
}
?>

View File

@ -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" )));
}
?>

View File

@ -2,72 +2,168 @@ $(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" );
}
},
close: function() {
true;
}
});
$( "#adduser-button" )
.click(function() {
$( "#adduser-form" ).dialog( "open" );
//#########################################################################
// 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 );
}
}
var newstring = newlist.join( ", " );
$(this).html( newstring )
});
}
//#########################################################################
// Clicking on buttons
//#########################################################################
// Show the create user form
$( "#createuseroptionbutton" )
.click(function(){
$( "#createuserform" ).toggle();
return false;
});
// Dialog for adding users
$( "#edituser-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Edit password": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
true;
}
});
$( ".edituser-button" )
// 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);
$("#edituser-form").dialog("open");
$("#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: 500,
width: 500,
modal: true,
buttons: {
"Edit user": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
true;
}
});
// 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;
});
} );

View File

@ -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>&nbsp;</td>
<td>&nbsp;</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>
</tr>
</thead>
<tfoot>
<tr>
<td><input type="text" name="groupname" id="creategroupname" /></td>
<td><input x-use="creategroupfield" type="text" name="groupname" /></td>
<td><button id="creategroupbutton">Create group</button></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>
<div id="adduser-form" title="Add user">
<form id="createuserdata">
<fieldset>
User 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>
</form>
</tfoot>
<tbody>
<?php foreach($_["groups"] as $group): ?>
<tr>
<td><?php echo $group["name"] ?></td>
<td x-gid="<?php echo $group["name"]; ?>"><a class="removegroupbutton" href="">remove</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<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>
</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>

View File

@ -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 ){