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

This commit is contained in:
Robin Appelman 2011-04-17 00:30:26 +02:00
commit 9c103ffa45
7 changed files with 129 additions and 31 deletions

View File

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

34
admin/ajax/createuser.php Normal file
View File

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

View 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;
});
} );

View 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();
?>

View 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>
@ -29,18 +29,18 @@
<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>
@ -55,25 +55,40 @@
<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>

View File

@ -27,6 +27,8 @@ and $_SESSION['username'] and strpos($dir,'..') === false){
}
}
echo json_encode(array( "status" => "error"));
$error = $_FILES['file']['error'];
echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error)));
?>

View File

@ -53,7 +53,7 @@ function uploadFinished() {
result = $('#file_upload_target').contents().text();
result = eval("(" + result + ");");
if(result.status == "error") {
alert('An error occcured, upload failed.');
alert('An error occcured, upload failed.\nError code: ' + result.data.error);
} else {
location.href = 'index.php?dir=' + $('#dir').val();
}