Browse Source

Move some common code to OC_Util

Created the following function:
 - checkLoggedIn
 - checkAdminUser
 - redirectToDefaultPage
tags/v3.0
Bart Visscher 12 years ago
parent
commit
e990ef3542

+ 2
- 5
apps/bookmarks/addBm.php View File

@@ -24,10 +24,7 @@
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();
$tmpl->printPage();

+ 2
- 5
apps/bookmarks/index.php View File

@@ -24,10 +24,7 @@
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();
$tmpl->printPage();

+ 2
- 5
apps/calendar/export.php View File

@@ -18,14 +18,11 @@
* 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);

+ 1
- 4
apps/calendar/index.php View File

@@ -18,10 +18,7 @@
* 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){

+ 1
- 4
apps/contacts/index.php View 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());

+ 1
- 4
apps/files_publiclink/admin.php View 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" );


+ 2
- 5
apps/files_sharing/list.php View File

@@ -23,10 +23,7 @@
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();

?>
?>

+ 1
- 4
apps/media/index.php View File

@@ -25,10 +25,7 @@
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');

+ 1
- 6
files/admin.php View File

@@ -25,12 +25,7 @@
// 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'])){

+ 1
- 4
files/ajax/download.php View File

@@ -25,10 +25,7 @@
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"];

+ 1
- 4
files/download.php View File

@@ -25,10 +25,7 @@
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"];


+ 1
- 4
files/index.php View File

@@ -26,10 +26,7 @@
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" );

+ 1
- 4
files/settings.php View File

@@ -26,10 +26,7 @@
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" );

+ 3
- 5
index.php View File

@@ -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"])){

+ 31
- 0
lib/util.php View 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();
}
}

+ 2
- 5
search/ajax/search.php View File

@@ -26,10 +26,7 @@
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';
}

?>
?>

+ 2
- 6
search/index.php View File

@@ -26,10 +26,7 @@
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();

+ 2
- 9
settings/admin.php View 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();
$tmpl->printPage();

+ 1
- 4
settings/apps.php View File

@@ -22,10 +22,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();

// Load the files we need
OC_Util::addStyle( "settings", "settings" );

+ 1
- 4
settings/help.php View 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

+ 1
- 4
settings/personal.php View 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" );

+ 2
- 5
settings/settings.php View 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();
$tmpl->printPage();

+ 1
- 4
settings/users.php View 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' );

Loading…
Cancel
Save