From e990ef35426b7dde59ec74eb1568a8cfbd69f316 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 18 Sep 2011 21:31:56 +0200 Subject: Move some common code to OC_Util Created the following function: - checkLoggedIn - checkAdminUser - redirectToDefaultPage --- lib/util.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/util.php') diff --git a/lib/util.php b/lib/util.php index 2f74bfe5841..51d8cc4d643 100644 --- a/lib/util.php +++ b/lib/util.php @@ -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(); + } } -- cgit v1.2.3