]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move some common code to OC_Util
authorBart Visscher <bart@thisnet.nl>
Sun, 18 Sep 2011 19:31:56 +0000 (21:31 +0200)
committerBart Visscher <bart@thisnet.nl>
Sun, 18 Sep 2011 19:31:56 +0000 (21:31 +0200)
Created the following function:
 - checkLoggedIn
 - checkAdminUser
 - redirectToDefaultPage

23 files changed:
apps/bookmarks/addBm.php
apps/bookmarks/index.php
apps/calendar/export.php
apps/calendar/index.php
apps/contacts/index.php
apps/files_publiclink/admin.php
apps/files_sharing/list.php
apps/media/index.php
files/admin.php
files/ajax/download.php
files/download.php
files/index.php
files/settings.php
index.php
lib/util.php
search/ajax/search.php
search/index.php
settings/admin.php
settings/apps.php
settings/help.php
settings/personal.php
settings/settings.php
settings/users.php

index 2dab33afb22d4351aba9f1696023c5e84f30eb2e..b62fcdfbeb0852fddc0970dccc52bc6032c3a82f 100644 (file)
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( 'Location: '.OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 require_once('bookmarksHelper.php');
 
@@ -45,4 +42,4 @@ $tmpl->assign('URL', htmlentities($metadata['url']));
 $tmpl->assign('TITLE', htmlentities($metadata['title']));
 $tmpl->assign('DESCRIPTION', htmlentities($metadata['description']));
 
-$tmpl->printPage();
\ No newline at end of file
+$tmpl->printPage();
index ba9f7cc0c618b5495c9dcba5b5b469eb020c212a..45c9a52f5577ae2fac249f3a60fcc3f56b045bc8 100644 (file)
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 OC_App::setActiveNavigationEntry( 'bookmarks_index' );
 
@@ -36,4 +33,4 @@ OC_Util::addStyle('bookmarks', 'bookmarks');
 
 $tmpl = new OC_Template( 'bookmarks', 'list', 'user' );
 
-$tmpl->printPage();
\ No newline at end of file
+$tmpl->printPage();
index f03a5d23e68f27cbb4274e24dca96a148aee0d51..d5ca5eeedad18f24b8c214fc8c47e5b6abfbba6f 100644 (file)
  * MA 02111-1307  USA                             *
  *************************************************/
 require_once ("../../lib/base.php");
-if(!OC_USER::isLoggedIn()) {
-       header("Location: " . OC_HELPER::linkTo("", "index.php"));
-       exit;
-} 
+OC_Util::checkLoggedIn();
 $cal = $_GET["calid"];
 $calendar = OC_Calendar_Calendar::findCalendar($cal);
 if($calendar["userid"] != OC_User::getUser()){
-       header("Location: " . OC_HELPER::linkTo("", "index.php"));
+       header( 'Location: '.OC_Helper::linkTo('', 'index.php'));
        exit;
 }
 $calobjects = OC_Calendar_Object::all($cal);
index c9fc9889d40e3f91d0f0298bafe1301a0f814a7e..c93ea93bb6cf513cf6be9e1511700caa439a8d45 100644 (file)
  * MA 02111-1307  USA                             *
  *************************************************/
 require_once ("../../lib/base.php");
-if(!OC_USER::isLoggedIn()) {
-       header("Location: " . OC_HELPER::linkTo("", "index.php"));
-       exit;
-}
+OC_Util::checkLoggedIn();
 // Create default calendar ...
 $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
 if( count($calendars) == 0){
index 8013f19d31ff7401f81de2a0bad560810757f4f1..c9cf348dfd7d4f3cdd5d25c19ac47bda2296e84f 100644 (file)
@@ -28,10 +28,7 @@ function contacts_namesort($a,$b){
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( 'Location: '.OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 // Check if the user has an addressbook
 $addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
index 33d8f04a603b0a2a8edc45745d58cd07266a452a..03d7a2ff6c5085c86264ea233aa4e6d680eb5a7d 100644 (file)
@@ -28,10 +28,7 @@ require_once( 'lib_public.php' );
 
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( "index.php" ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 OC_App::setActiveNavigationEntry( "files_publiclink_administration" );
 
index 0a11f438eb7b59073a72b419e3584a9266e3a880..a5f99f3804110131b148853f915bbfe43a294be6 100644 (file)
 require_once('../../lib/base.php');
 require_once('lib_share.php');
 
-if (!OC_User::isLoggedIn()){
-       header( "Location: ".OC_HELPER::linkTo( "index.php" ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 OC_App::setActiveNavigationEntry("files_sharing_list");
 
@@ -36,4 +33,4 @@ $tmpl = new OC_Template("files_sharing", "list", "user");
 $tmpl->assign("shared_items", OC_Share::getMySharedItems());
 $tmpl->printPage();
 
-?>
\ No newline at end of file
+?>
index fe724b45ddf2e850809e35be21a3d30f8fa73d44..578ab7e3c341776ad5739ea0f7c330d2962da1d3 100644 (file)
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 require_once('lib_collection.php');
 require_once('lib_scanner.php');
index db47bc7c033584cf5fa40f319a99dc0d4580dcce..09237dfc1d50c2fe0b30c5b71ab2edaf56aa8db9 100644 (file)
 // Init owncloud
 require_once('../lib/base.php');
 
-
-// Check if we are a user
-if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
-       header( "Location: ".OC_Helper::linkTo( "files", "index.php" ));
-       exit();
-}
+OC_User::checkAdminUser();
 
 $htaccessWorking=(getenv('htaccessWorking')=='true');
 if(isset($_POST['maxUploadSize'])){
index 4c756f9b1905570f7900cea78a3a9f15a59beff1..198069f3fa1c212a83360a13443fdfe39f867c97 100644 (file)
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 $files = $_GET["files"];
 $dir = $_GET["dir"];
index ccd3eb43d8e7bac556c2d274823ab5f624f671f5..c8a2692d015359e27e5a9304c07a7dc47e03f9e1 100644 (file)
 require_once('../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 $filename = $_GET["file"];
 
index 3d62c3385faf60c64ea8e20dde8be3f82cd41544..bba8dc4951e059227b9aa37e45d2804ffda8361d 100644 (file)
 require_once('../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 // Load the files we need
 OC_Util::addStyle( "files", "files" );
index 2bbcb2acd3aec2e178fa165339e4845d449c11d6..c47eb130095a236b5c38135f5809ee13838c9e7d 100644 (file)
 require_once('../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 // Load the files we need
 OC_Util::addStyle( "files", "files" );
index 46105a106fbb0207c224c2c25b4c914280cb7a51..23bc4fb7764c3434d7e9e48cb70c3a2e22be5ab7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -48,8 +48,7 @@ elseif(OC_User::isLoggedIn()) {
                exit();
        }
        else {
-               header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
-               exit();
+               OC_Util::redirectToDefaultPage();
        }
 }
 
@@ -61,7 +60,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) {
        if(OC_User::userExists($_COOKIE['oc_username']) &&
           OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) {
                OC_User::setUserId($_COOKIE['oc_username']);
-               header("Location: ". OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
+               OC_Util::redirectToDefaultPage();
        }
        else {
                OC_Template::printGuestPage("", "login", array("error" => true));
@@ -72,7 +71,6 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) {
 elseif(isset($_POST["user"]) && isset($_POST['password'])) {
        OC_App::loadApps();
        if(OC_User::login($_POST["user"], $_POST["password"])) {
-               header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
                if(!empty($_POST["remember_login"])){
                        error_log("Setting remember login to cookie");
                        $token = md5($_POST["user"].time());
@@ -82,7 +80,7 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) {
                else {
                        OC_User::unsetMagicInCookie();
                }
-               exit();
+               OC_Util::redirectToDefaultPage();
        }
        else {
                if(isset($_COOKIE["oc_username"])){
index 2f74bfe5841bce17c6589ba4d896f7e4b0f21bc3..51d8cc4d64311abe2c28679473bfc2e9220f5192 100644 (file)
@@ -246,4 +246,35 @@ class OC_Util {
 
                return $errors;
        }
+
+       /**
+       * Check if the user is logged in, redirects to home if not
+       */
+       public static function checkLoggedIn(){
+               // Check if we are a user
+               if( !OC_User::isLoggedIn()){
+                       header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true));
+                       exit();
+               }
+       }
+
+       /**
+       * Check if the user is a admin, redirects to home if not
+       */
+       public static function checkAdminUser(){
+               // Check if we are a user
+               self::checkLoggedIn();
+               if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
+                       header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true));
+                       exit();
+               }
+       }
+
+       /**
+       * Redirect to the user default page
+       */
+       public static function redirectToDefaultPage(){
+               header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php'));
+               exit();
+       }
 }
index c65fbbc63fa9ba456cb6dc10012f48fc0e3b9f8e..9472f97e18980637a3f45e5d9e8da4d1bcaeb940 100644 (file)
 require_once('../../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 $query=(isset($_GET['query']))?$_GET['query']:'';
 if($query){
@@ -39,4 +36,4 @@ if($query){
        echo 'false';
 }
 
-?>
\ No newline at end of file
+?>
index c781c31f549894984735786d3ae82241588e0a08..518695c56d202d4dab7bc27f6ac1496d9578a63b 100644 (file)
 require_once('../lib/base.php');
 
 // Check if we are a user
-if( !OC_User::isLoggedIn()){
-       header( "Location: ".OC_Helper::linkTo( '', 'index.php' ));
-       exit();
-}
+OC_Util::checkLoggedIn();
 
 // Load the files we need
 OC_Util::addStyle( 'search', 'search' );
@@ -38,8 +35,7 @@ $query=(isset($_POST['query']))?$_POST['query']:'';
 if($query){
        $results=OC_Search::search($query);
 }else{
-       header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php"));
-       exit();
+       OC_Util::redirectToDefaultPage();
 }
 
 $resultTypes=array();
index 15559a150e5ea80077053ec600891b4cbbb4bdfa..81ed6aa9516487ab3b8ed8963a6eaf9a8959720f 100644 (file)
@@ -6,14 +6,7 @@
  */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn()){
-    header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-    exit();
-}
-if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
-       header( "Location: ".OC_Helper::linkTo( '', "index.php" ));
-       exit();
-}
+OC_Util::checkAdminUser();
 
 OC_Util::addStyle( "settings", "settings" );
 OC_App::setActiveNavigationEntry( "admin" );
@@ -24,4 +17,4 @@ $tmpl->assign('forms',array());
 foreach($forms as $form){
        $tmpl->append('forms',$form);
 }
-$tmpl->printPage();
\ No newline at end of file
+$tmpl->printPage();
index 337a52fd41630932cc30fff8361c6cf72a3292f2..672cb18775e3c23641735c09ea8ef25a26387345 100644 (file)
 */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
-       header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-       exit();
-}
+OC_Util::checkAdminUser();
 
 // Load the files we need
 OC_Util::addStyle( "settings", "settings" );
index f8a2f9b8bf959d2eea9183dc1efcc8b420f080cc..48fcec32782bd9a9dcca3aedeea80cf269ee3d40 100644 (file)
@@ -6,10 +6,7 @@
  */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn()){
-    header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-    exit();
-}
+OC_Util::checkLoggedIn();
 
 
 // Load the files we need
index e6d2d44db761b453c1f88de95fcd9e7c18b4feb5..aea997aff227384f7ede8024e39ad58318469492 100644 (file)
@@ -6,10 +6,7 @@
  */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn()){
-    header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-    exit();
-}
+OC_Util::checkLoggedIn();
 
 // Highlight navigation entry
 OC_Util::addScript( "settings", "personal" );
index 724cf63aaf70c4a93106c535c09814b712cf374d..b08cb08db09b10a596a7b81833f218f28ba3d6e0 100644 (file)
@@ -6,10 +6,7 @@
  */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn()){
-    header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-    exit();
-}
+OC_Util::checkLoggedIn();
 
 OC_Util::addStyle( "settings", "settings" );
 OC_App::setActiveNavigationEntry( "settings" );
@@ -20,4 +17,4 @@ $tmpl->assign('forms',array());
 foreach($forms as $form){
        $tmpl->append('forms',$form);
 }
-$tmpl->printPage();
\ No newline at end of file
+$tmpl->printPage();
index 5aae4ce43effd9a8301770d6c5eaa7dfaeb517fe..9ca2cb369f7e1d4ad61e639f7996d22e8484b54d 100644 (file)
@@ -6,10 +6,7 @@
  */
 
 require_once('../lib/base.php');
-if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){
-       header( "Location: ".OC_Helper::linkTo( "", "index.php" ));
-       exit();
-}
+OC_Util::checkAdminUser();
 
 // We have some javascript foo!
 OC_Util::addScript( 'settings', 'users' );