diff options
author | Bart Visscher <bart@thisnet.nl> | 2011-09-18 21:31:56 +0200 |
---|---|---|
committer | Bart Visscher <bart@thisnet.nl> | 2011-09-18 21:31:56 +0200 |
commit | e990ef35426b7dde59ec74eb1568a8cfbd69f316 (patch) | |
tree | 9b4a276885378540812ce93c3cddcc73a00ba3b0 /lib/util.php | |
parent | 8966ed5a004a9b830f093355170d381566d58554 (diff) | |
download | nextcloud-server-e990ef35426b7dde59ec74eb1568a8cfbd69f316.tar.gz nextcloud-server-e990ef35426b7dde59ec74eb1568a8cfbd69f316.zip |
Move some common code to OC_Util
Created the following function:
- checkLoggedIn
- checkAdminUser
- redirectToDefaultPage
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 31 |
1 files changed, 31 insertions, 0 deletions
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(); + } } |