diff options
Diffstat (limited to 'settings/ajax')
-rw-r--r-- | settings/ajax/changepassword.php | 31 | ||||
-rw-r--r-- | settings/ajax/creategroup.php | 31 | ||||
-rw-r--r-- | settings/ajax/createuser.php | 42 | ||||
-rw-r--r-- | settings/ajax/disableapp.php | 8 | ||||
-rw-r--r-- | settings/ajax/enableapp.php | 9 | ||||
-rw-r--r-- | settings/ajax/removegroup.php | 25 | ||||
-rw-r--r-- | settings/ajax/removeuser.php | 25 | ||||
-rw-r--r-- | settings/ajax/togglegroups.php | 48 |
8 files changed, 198 insertions, 21 deletions
diff --git a/settings/ajax/changepassword.php b/settings/ajax/changepassword.php index b9b2417ad9a..98c2a8b37a1 100644 --- a/settings/ajax/changepassword.php +++ b/settings/ajax/changepassword.php @@ -3,35 +3,24 @@ // Init owncloud require_once('../../lib/base.php'); -$l=new OC_L10N('settings'); - // We send json data -header("Content-Type: application/jsonrequest"); +header( "Content-Type: application/jsonrequest" ); // Check if we are a user -if(!OC_User::isLoggedIn()){ - echo json_encode(array("status" => "error", "data" => array("message" => $l->t("Authentication error")))); +if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); exit(); } -// Get data -if(!isset($_POST["password"]) && !isset($_POST["oldpassword"])){ - echo json_encode(array("status" => "error", "data" => array("message" => $l->t("You have to enter the old and the new password!")))); - exit(); -} +$username = $_POST["username"]; +$password = $_POST["password"]; -// Check if the old password is correct -if(!OC_User::checkPassword($_SESSION["user_id"], $_POST["oldpassword"])){ - echo json_encode(array("status" => "error", "data" => array("message" => $l->t("Your old password is wrong!")))); - exit(); +// Return Success story +if( OC_User::setPassword( $username, $password )){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $username ))); } - -// Change password -if(OC_User::setPassword($_SESSION["user_id"], $_POST["password"])){ - echo json_encode(array("status" => "success", "data" => array("message" => $l->t("Password changed")))); - OC_Crypt::changekeypasscode($_POST["password"]); -}else{ - echo json_encode(array("status" => "error", "data" => array("message" => $l->t("Unable to change password")))); +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to change password" ))); } ?> diff --git a/settings/ajax/creategroup.php b/settings/ajax/creategroup.php new file mode 100644 index 00000000000..2631937b14d --- /dev/null +++ b/settings/ajax/creategroup.php @@ -0,0 +1,31 @@ +<?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( OC_User::getUser(), 'admin' )){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$groupname = $_POST["groupname"]; + +// Does the group exist? +if( in_array( $groupname, OC_Group::getGroups())){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Group already exists" ))); + exit(); +} + +// Return Success story +if( OC_Group::createGroup( $groupname )){ + echo json_encode( array( "status" => "success", "data" => array( "groupname" => $groupname ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add group" ))); +} + +?> diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php new file mode 100644 index 00000000000..de52f90d4f3 --- /dev/null +++ b/settings/ajax/createuser.php @@ -0,0 +1,42 @@ +<?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( OC_User::getUser(), '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"]; + +// Does the group exist? +if( in_array( $username, OC_User::getUsers())){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "User already exists" ))); + exit(); +} + +// Return Success story +if( OC_User::createUser( $username, $password )){ + foreach( $groups as $i ){ + if(!OC_Group::groupExists($i)){ + OC_Group::createGroup($i); + } + OC_Group::addToGroup( $username, $i ); + } + echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", OC_Group::getUserGroups( $username ))))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add user" ))); +} + +?> diff --git a/settings/ajax/disableapp.php b/settings/ajax/disableapp.php new file mode 100644 index 00000000000..0cf66a553f8 --- /dev/null +++ b/settings/ajax/disableapp.php @@ -0,0 +1,8 @@ +<?php +// Init owncloud +require_once('../../lib/base.php'); +header( "Content-Type: application/jsonrequest" ); + +OC_App::disable($_POST['appid']); + +?> diff --git a/settings/ajax/enableapp.php b/settings/ajax/enableapp.php new file mode 100644 index 00000000000..eb1bfc54a04 --- /dev/null +++ b/settings/ajax/enableapp.php @@ -0,0 +1,9 @@ +<?php + +// Init owncloud +require_once('../../lib/base.php'); +header( "Content-Type: application/jsonrequest" ); + +OC_App::enable($_POST['appid']); + +?> diff --git a/settings/ajax/removegroup.php b/settings/ajax/removegroup.php new file mode 100644 index 00000000000..bf80da741c7 --- /dev/null +++ b/settings/ajax/removegroup.php @@ -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( OC_User::getUser(), 'admin' )){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$name = $_POST["groupname"]; + +// Return Success story +if( OC_Group::deleteGroup( $name )){ + echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete group" ))); +} + +?> diff --git a/settings/ajax/removeuser.php b/settings/ajax/removeuser.php new file mode 100644 index 00000000000..0a94884cb96 --- /dev/null +++ b/settings/ajax/removeuser.php @@ -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( OC_User::getUser(), 'admin' )){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$username = $_POST["username"]; + +// Return Success story +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" => "Unable to delete user" ))); +} + +?> diff --git a/settings/ajax/togglegroups.php b/settings/ajax/togglegroups.php new file mode 100644 index 00000000000..3210252af02 --- /dev/null +++ b/settings/ajax/togglegroups.php @@ -0,0 +1,48 @@ +<?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( OC_User::getUser(), 'admin' )){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$success = true; +$error = "add user to"; +$action = "add"; + +$username = $_POST["username"]; +$group = $_POST["group"]; + +if(!OC_Group::groupExists($group)){ + OC_Group::createGroup($group); +} + +// Toggle group +if( OC_Group::inGroup( $username, $group )){ + $action = "remove"; + $error = "remove user from"; + $success = OC_Group::removeFromGroup( $username, $group ); + $usersInGroup=OC_Group::usersInGroup($group); + if(count($usersInGroup)==0){ + OC_Group::deleteGroup($group); + } +} +else{ + $success = OC_Group::addToGroup( $username, $group ); +} + +// Return Success story +if( $success ){ + echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "action" => $action, "groupname" => $group ))); +} +else{ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to $error group $group" ))); +} + +?> |