diff options
Diffstat (limited to 'settings/ajax')
-rw-r--r-- | settings/ajax/changepassword.php | 12 | ||||
-rw-r--r-- | settings/ajax/creategroup.php | 11 | ||||
-rw-r--r-- | settings/ajax/createuser.php | 11 | ||||
-rw-r--r-- | settings/ajax/disableapp.php | 2 | ||||
-rw-r--r-- | settings/ajax/enableapp.php | 2 | ||||
-rw-r--r-- | settings/ajax/openid.php | 13 | ||||
-rw-r--r-- | settings/ajax/removegroup.php | 13 | ||||
-rw-r--r-- | settings/ajax/removeuser.php | 13 | ||||
-rw-r--r-- | settings/ajax/setlanguage.php | 13 | ||||
-rw-r--r-- | settings/ajax/setquota.php | 11 | ||||
-rw-r--r-- | settings/ajax/togglegroups.php | 13 |
11 files changed, 32 insertions, 82 deletions
diff --git a/settings/ajax/changepassword.php b/settings/ajax/changepassword.php index 98218b9f89e..860ea987871 100644 --- a/settings/ajax/changepassword.php +++ b/settings/ajax/changepassword.php @@ -3,25 +3,23 @@ // Init owncloud require_once('../../lib/base.php'); -// We send json data -header( "Content-Type: application/jsonrequest" ); - $username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser(); $password = $_POST["password"]; $oldPassword=isset($_POST["oldpassword"])?$_POST["oldpassword"]:''; // Check if we are a user -if( !OC_User::isLoggedIn() || (!OC_Group::inGroup( OC_User::getUser(), 'admin' ) && ($username!=OC_User::getUser() || !OC_User::checkPassword($username,$oldPassword)))) { - echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); +OC_JSON::checkLoggedIn(); +if( (!OC_Group::inGroup( OC_User::getUser(), 'admin' ) && ($username!=OC_User::getUser() || !OC_User::checkPassword($username,$oldPassword)))) { + OC_JSON::error( array( "data" => array( "message" => "Authentication error" ))); exit(); } // Return Success story if( OC_User::setPassword( $username, $password )){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $username ))); + OC_JSON::success(array("data" => array( "username" => $username ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to change password" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to change password" ))); } ?> diff --git a/settings/ajax/creategroup.php b/settings/ajax/creategroup.php index 2631937b14d..57d82e7bd94 100644 --- a/settings/ajax/creategroup.php +++ b/settings/ajax/creategroup.php @@ -3,12 +3,9 @@ // 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" ))); + OC_JSON::error(array("data" => array( "message" => "Authentication error" ))); exit(); } @@ -16,16 +13,16 @@ $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" ))); + OC_JSON::error(array("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 ))); + OC_JSON::success(array("data" => array( "groupname" => $groupname ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add group" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to add group" ))); } ?> diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index de52f90d4f3..1ed53efcf06 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -3,12 +3,9 @@ // 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" ))); + OC_JSON::error(array("data" => array( "message" => "Authentication error" ))); exit(); } @@ -21,7 +18,7 @@ $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" ))); + OC_JSON::error(array("data" => array( "message" => "User already exists" ))); exit(); } @@ -33,10 +30,10 @@ if( OC_User::createUser( $username, $password )){ } OC_Group::addToGroup( $username, $i ); } - echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "groups" => implode( ", ", OC_Group::getUserGroups( $username ))))); + OC_JSON::success(array("data" => array( "username" => $username, "groups" => implode( ", ", OC_Group::getUserGroups( $username ))))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to add user" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to add user" ))); } ?> diff --git a/settings/ajax/disableapp.php b/settings/ajax/disableapp.php index 0cf66a553f8..12f6b32a4f3 100644 --- a/settings/ajax/disableapp.php +++ b/settings/ajax/disableapp.php @@ -1,7 +1,7 @@ <?php // Init owncloud require_once('../../lib/base.php'); -header( "Content-Type: application/jsonrequest" ); +OC_JSON::setContentTypeHeader(); OC_App::disable($_POST['appid']); diff --git a/settings/ajax/enableapp.php b/settings/ajax/enableapp.php index eb1bfc54a04..8be80cd2ece 100644 --- a/settings/ajax/enableapp.php +++ b/settings/ajax/enableapp.php @@ -2,7 +2,7 @@ // Init owncloud require_once('../../lib/base.php'); -header( "Content-Type: application/jsonrequest" ); +OC_JSON::setContentTypeHeader(); OC_App::enable($_POST['appid']); diff --git a/settings/ajax/openid.php b/settings/ajax/openid.php index 021fe35d8ec..4226ae740f0 100644 --- a/settings/ajax/openid.php +++ b/settings/ajax/openid.php @@ -5,22 +5,15 @@ require_once('../../lib/base.php'); $l=new OC_L10N('settings'); -// We send json data -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") ))); - exit(); -} +OC_JSON::checkLoggedIn(); // Get data if( isset( $_POST['identity'] ) ){ $identity=$_POST['identity']; OC_Preferences::setValue(OC_User::getUser(),'user_openid','identity',$identity); - echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("OpenID Changed") ))); + OC_JSON::success(array("data" => array( "message" => $l->t("OpenID Changed") ))); }else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Invalid request") ))); + OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") ))); } ?> diff --git a/settings/ajax/removegroup.php b/settings/ajax/removegroup.php index bf80da741c7..4d364781894 100644 --- a/settings/ajax/removegroup.php +++ b/settings/ajax/removegroup.php @@ -3,23 +3,16 @@ // 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(); -} +OC_JSON::checkAdminUser(); $name = $_POST["groupname"]; // Return Success story if( OC_Group::deleteGroup( $name )){ - echo json_encode( array( "status" => "success", "data" => array( "groupname" => $name ))); + OC_JSON::success(array("data" => array( "groupname" => $name ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete group" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to delete group" ))); } ?> diff --git a/settings/ajax/removeuser.php b/settings/ajax/removeuser.php index 0a94884cb96..2c288997a1f 100644 --- a/settings/ajax/removeuser.php +++ b/settings/ajax/removeuser.php @@ -3,23 +3,16 @@ // 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(); -} +OC_JSON::checkAdminUser(); $username = $_POST["username"]; // Return Success story if( OC_User::deleteUser( $username )){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $username ))); + OC_JSON::success(array("data" => array( "username" => $username ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to delete user" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to delete user" ))); } ?> diff --git a/settings/ajax/setlanguage.php b/settings/ajax/setlanguage.php index a5ba3d81ba3..dc1128de2e5 100644 --- a/settings/ajax/setlanguage.php +++ b/settings/ajax/setlanguage.php @@ -5,22 +5,15 @@ require_once('../../lib/base.php'); $l=new OC_L10N('settings'); -// We send json data -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") ))); - exit(); -} +OC_JSON::checkLoggedIn(); // Get data if( isset( $_POST['lang'] ) ){ $lang=$_POST['lang']; OC_Preferences::setValue( OC_User::getUser(), 'core', 'lang', $lang ); - echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Language changed") ))); + OC_JSON::success(array("data" => array( "message" => $l->t("Language changed") ))); }else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Invalid request") ))); + OC_JSON::error(array("data" => array( "message" => $l->t("Invalid request") ))); } ?> diff --git a/settings/ajax/setquota.php b/settings/ajax/setquota.php index 244a85e3d9c..edbf5b74516 100644 --- a/settings/ajax/setquota.php +++ b/settings/ajax/setquota.php @@ -3,20 +3,13 @@ // 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(); -} +OC_JSON::checkAdminUser(); $username = $_POST["username"]; $quota= OC_Helper::computerFileSize($_POST["quota"]); // Return Success story OC_Preferences::setValue($username,'files','quota',$quota); -echo json_encode( array( "status" => "success", "data" => array( "username" => $username ,'quota'=>$quota))); +OC_JSON::success(array("data" => array( "username" => $username ,'quota'=>$quota))); ?> diff --git a/settings/ajax/togglegroups.php b/settings/ajax/togglegroups.php index 3210252af02..3ee3239dd89 100644 --- a/settings/ajax/togglegroups.php +++ b/settings/ajax/togglegroups.php @@ -3,14 +3,7 @@ // 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(); -} +OC_JSON::checkAdminUser(); $success = true; $error = "add user to"; @@ -39,10 +32,10 @@ else{ // Return Success story if( $success ){ - echo json_encode( array( "status" => "success", "data" => array( "username" => $username, "action" => $action, "groupname" => $group ))); + OC_JSON::success(array("data" => array( "username" => $username, "action" => $action, "groupname" => $group ))); } else{ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Unable to $error group $group" ))); + OC_JSON::error(array("data" => array( "message" => "Unable to $error group $group" ))); } ?> |