diff --git a/apps/calendar/ajax/activation.php b/apps/calendar/ajax/activation.php
index 3c2bc6de23ffa82868af31463a35bdd403df15c0..ada2e44547bcf6ca46ac987c5e86c9d980d45955 100644
--- a/apps/calendar/ajax/activation.php
+++ b/apps/calendar/ajax/activation.php
@@ -7,9 +7,7 @@
  */
 
 require_once ("../../../lib/base.php");
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $calendarid = $_POST['calendarid'];
 $calendar = OC_Calendar_App::getCalendar($calendarid);//access check
diff --git a/apps/calendar/ajax/choosecalendar.php b/apps/calendar/ajax/choosecalendar.php
index 0935a4c42ade0eb9036ba75ed714fffa6ccef44e..9281c8edbdcf5b1160be02998a2c7b7209cbe1e0 100644
--- a/apps/calendar/ajax/choosecalendar.php
+++ b/apps/calendar/ajax/choosecalendar.php
@@ -8,9 +8,7 @@
 
 require_once('../../../lib/base.php');
 $l10n = new OC_L10N('calendar');
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $output = new OC_TEMPLATE("calendar", "part.choosecalendar");
 $output -> printpage();
diff --git a/apps/calendar/ajax/deletecalendar.php b/apps/calendar/ajax/deletecalendar.php
index fc308da6dadfc4415d56c33c62d4916a25ca436d..901cbbfcb08e95de7e1908e134a64ecf9b58a12a 100644
--- a/apps/calendar/ajax/deletecalendar.php
+++ b/apps/calendar/ajax/deletecalendar.php
@@ -7,9 +7,7 @@
  */
 require_once('../../../lib/base.php');
 
-if(!OC_USER::isLoggedIn()) {
-	die('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $cal = $_POST["calendarid"];
diff --git a/apps/calendar/ajax/deleteevent.php b/apps/calendar/ajax/deleteevent.php
index 269f4a47f42d51f6dc573fa744a8a602079cd9c3..b25a5af1a291921659db3b3a78a6d87918b44a9c 100644
--- a/apps/calendar/ajax/deleteevent.php
+++ b/apps/calendar/ajax/deleteevent.php
@@ -9,9 +9,7 @@ require_once('../../../lib/base.php');
 
 $l10n = new OC_L10N('calendar');
 
-if(!OC_USER::isLoggedIn()) {
-	die('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $id = $_POST['id'];
diff --git a/apps/calendar/ajax/editcalendar.php b/apps/calendar/ajax/editcalendar.php
index e44763c9aaac5931f226c5358e9037ecb3dfb32e..7aeb5bbe30557223e49a0fccc461a15ad8c0c713 100644
--- a/apps/calendar/ajax/editcalendar.php
+++ b/apps/calendar/ajax/editcalendar.php
@@ -7,9 +7,7 @@
  */
 
 require_once('../../../lib/base.php');
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();
diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php
index f00ab1d960b6a5be8725a376aeb360ddbfdcb8cc..5a487da17588ff369ab380badfe8dd5921df627c 100644
--- a/apps/calendar/ajax/editevent.php
+++ b/apps/calendar/ajax/editevent.php
@@ -7,9 +7,7 @@
  */
 
 require_once('../../../lib/base.php');
-if(!OC_USER::isLoggedIn()) {
-	die('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $errarr = OC_Calendar_Object::validateRequest($_POST);
diff --git a/apps/calendar/ajax/editeventform.php b/apps/calendar/ajax/editeventform.php
index fe6c6f7357003804049542b0124c374f48ed7dde..2c81539d2e05b8b22c2a1dc6687af22047746d12 100644
--- a/apps/calendar/ajax/editeventform.php
+++ b/apps/calendar/ajax/editeventform.php
@@ -8,9 +8,7 @@
 
 require_once('../../../lib/base.php');
 
-if(!OC_USER::isLoggedIn()) {
-	die('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $id = $_GET['id'];
diff --git a/apps/calendar/ajax/importdialog.php b/apps/calendar/ajax/importdialog.php
index 232b4ba580741524b8700c43e6fa3dd2444d5864..8d8430da7aa9df137af187fa198208ea56b67f78 100644
--- a/apps/calendar/ajax/importdialog.php
+++ b/apps/calendar/ajax/importdialog.php
@@ -10,9 +10,7 @@ require_once('../../../lib/base.php');
 
 $l10n = new OC_L10N('calendar');
 
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $tmpl = new OC_Template('calendar', 'part.import');
diff --git a/apps/calendar/ajax/newcalendar.php b/apps/calendar/ajax/newcalendar.php
index a7935c956729c29e85da7d18a85dbaae3df1bad4..af3ba4fbbeabdc84f17d82a34c23aaec81f56b3a 100644
--- a/apps/calendar/ajax/newcalendar.php
+++ b/apps/calendar/ajax/newcalendar.php
@@ -8,9 +8,7 @@
 
 require_once('../../../lib/base.php');
 $l10n = new OC_L10N('calendar');
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();
 $calendar = array(
diff --git a/apps/calendar/ajax/newevent.php b/apps/calendar/ajax/newevent.php
index 1a696cf7780f8e9a25392a7717227bd955af8960..c7c4d29943a0b3daf783b1801df20349197ff193 100644
--- a/apps/calendar/ajax/newevent.php
+++ b/apps/calendar/ajax/newevent.php
@@ -10,9 +10,7 @@ require_once('../../../lib/base.php');
 
 $l10n = new OC_L10N('calendar');
 
-if(!OC_USER::isLoggedIn()) {
-	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 $errarr = OC_Calendar_Object::validateRequest($_POST);
diff --git a/apps/calendar/ajax/neweventform.php b/apps/calendar/ajax/neweventform.php
index e12e99219e67ec0b3d8316df0a95e23d241956fd..6de1f8ca3073a3d54250726615d074decdec8f43 100644
--- a/apps/calendar/ajax/neweventform.php
+++ b/apps/calendar/ajax/neweventform.php
@@ -8,9 +8,7 @@
 
 require_once('../../../lib/base.php');
 
-if(!OC_USER::isLoggedIn()) {
-	die('<script type="text/javascript">document.location = oc_webroot;</script>');
-}
+OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
 if (!isset($_POST['start'])){