removeuser.php 698 B

123456789101112131415161718192021222324252627
  1. <?php
  2. OC_JSON::checkSubAdminUser();
  3. OCP\JSON::callCheck();
  4. $username = $_POST["username"];
  5. // A user shouldn't be able to delete his own account
  6. if(OC_User::getUser() === $username) {
  7. exit;
  8. }
  9. if(!OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
  10. $l = OC_L10N::get('core');
  11. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
  12. exit();
  13. }
  14. // Return Success story
  15. if( OC_User::deleteUser( $username )) {
  16. OC_JSON::success(array("data" => array( "username" => $username )));
  17. }
  18. else{
  19. $l = OC_L10N::get('core');
  20. OC_JSON::error(array("data" => array( "message" => $l->t("Unable to delete user") )));
  21. }