예제 #1
0
 public function postDelete()
 {
     Auth::getUser()->hasPermissionOr401(Config::get("permissions.users"), 1);
     $resp = array("success" => false);
     if (FormHelpers::hasPost("id")) {
         $id = intval($_POST["id"], 10);
         DB::transaction(function () use(&$id, &$resp) {
             $user = User::find($id);
             if (!is_null($user)) {
                 if (!$user->resultsInNoAccessibleAdminLogin(true)) {
                     if ($user->delete() === false) {
                         throw new Exception("Error deleting User.");
                     }
                     $resp['success'] = true;
                 } else {
                     $resp['msg'] = "This user cannot be deleted at the moment as it would result in no admin with access to the system.";
                 }
             }
         });
     }
     return Response::json($resp);
 }