add oc_user::getUser to get the user id of the loggedin user

This commit is contained in:
Robin Appelman 2011-06-22 12:50:57 +02:00
parent c0af177223
commit 83958ebd4b
17 changed files with 35 additions and 22 deletions

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -7,7 +7,7 @@ require_once('../../lib/base.php');
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
exit();
}

View file

@ -24,7 +24,7 @@
require_once('../lib/base.php');
include_once('../lib/installer.php');
require( 'template.php' );
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
header( "Location: ".OC_HELPER::linkTo( "", "index.php" ));
exit();
}

View file

@ -23,7 +23,7 @@
require_once('../lib/base.php');
require( 'template.php' );
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
header( "Location: ".OC_HELPER::linkTo( "index.php" ));
exit();
}

View file

@ -23,7 +23,7 @@
require_once('../lib/base.php');
require( 'template.php' );
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
header( "Location: ".OC_HELPER::linkTo( "index.php" ));
exit();
}

View file

@ -7,7 +7,7 @@ class OC_PublicLink{
*/
public function __construct($path,$expiretime=0){
if($path and OC_FILESYSTEM::file_exists($path) and OC_FILESYSTEM::is_readable($path)){
$user=$_SESSION['user_id'];
$user=OC_USER::getUser();
$token=sha1("$user-$path-$expiretime");
$query=OC_DB::prepare("INSERT INTO *PREFIX*publiclink VALUES(?,?,?,?)");
$result=$query->execute(array($token,$path,$user,$expiretime));
@ -60,7 +60,7 @@ class OC_PublicLink{
*/
static public function getLinks(){
$query=OC_DB::prepare("SELECT * FROM *PREFIX*publiclink WHERE user=?");
return $query->execute(array($_SESSION['user_id']))->fetchAll();
return $query->execute(array(OC_USER::getUser()))->fetchAll();
}
/**
@ -69,7 +69,7 @@ class OC_PublicLink{
static public function delete($token){
$query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?");
$result=$query->execute(array($token))->fetchAll();
if(count($result)>0 and $result[0]['user']==$_SESSION['user_id']){
if(count($result)>0 and $result[0]['user']==OC_USER::getUser()){
$query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE token=?");
$query->execute(array($token));
}

View file

@ -28,7 +28,7 @@ require( 'template.php' );
// Check if we are a user
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( OC_USER::getUser(), 'admin' )){
header( "Location: ".OC_HELPER::linkTo( "index.php" ));
exit();
}

View file

@ -142,7 +142,7 @@ class OC_UTIL {
// If we are not forced to load a specific user we load the one that is logged in
if( $user == "" && OC_USER::isLoggedIn()){
$user = $_SESSION['user_id'];
$user = OC_USER::getUser();
}
if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem

View file

@ -200,8 +200,8 @@ class OC_L10N{
else{
$available=self::findAvailableLanguages( $app );
}
if( isset($_SESSION['user_id']) && $_SESSION['user_id'] && OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang' )){
$lang = OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang' );
if( OC_USER::getUser() && OC_PREFERENCES::getValue( OC_USER::getUser(), 'core', 'lang' )){
$lang = OC_PREFERENCES::getValue( OC_USER::getUser(), 'core', 'lang' );
self::$language = $lang;
if( array_search( $lang, $available ) !== false ){
return $lang;

View file

@ -231,6 +231,19 @@ class OC_USER {
}
}
/**
* @brief get the user idea of the user currently logged in.
* @return string uid or false
*/
public static function getUser(){
if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ){
return $_SESSION['user_id'];
}
else{
return false;
}
}
/**
* @brief Autogenerate a password
* @returns string

View file

@ -43,8 +43,8 @@ if(isset($_POST['save'])){
$selectedActions[]=$action;
}
}
OC_PREFERENCES::setValue($_SESSION['user_id'],'log','actions',implode(',',$selectedActions));
OC_PREFERENCES::setValue($_SESSION['user_id'],'log','pagesize',$_POST['size']);
OC_PREFERENCES::setValue(OC_USER::getUser(),'log','actions',implode(',',$selectedActions));
OC_PREFERENCES::setValue(OC_USER::getUser(),'log','pagesize',$_POST['size']);
}
//clear log entries
elseif(isset($_POST['clear'])){
@ -62,10 +62,10 @@ OC_APP::setActiveNavigationEntry( 'log' );
$logs=OC_LOG::get();
$selectedActions=explode(',',OC_PREFERENCES::getValue($_SESSION['user_id'],'log','actions',implode(',',$allActions)));
$selectedActions=explode(',',OC_PREFERENCES::getValue(OC_USER::getUser(),'log','actions',implode(',',$allActions)));
$logs=OC_LOG::filterAction($logs,$selectedActions);
$pageSize=OC_PREFERENCES::getValue($_SESSION['user_id'],'log','pagesize',20);
$pageSize=OC_PREFERENCES::getValue(OC_USER::getUser(),'log','pagesize',20);
$pageCount=ceil(count($logs)/$pageSize);
$page=isset($_GET['page'])?$_GET['page']:0;
if($page>=$pageCount){

View file

@ -17,7 +17,7 @@ if( !OC_USER::isLoggedIn()){
// Get data
if( isset( $_POST['lang'] ) ){
$lang=$_POST['lang'];
OC_PREFERENCES::setValue( $_SESSION['user_id'], 'core', 'lang', $lang );
OC_PREFERENCES::setValue( OC_USER::getUser(), 'core', 'lang', $lang );
echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Language changed") )));
}else{
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Invalid request") )));

View file

@ -18,7 +18,7 @@ $free=OC_FILESYSTEM::free_space();
$total=$free+$used;
$relative=round(($used/$total)*100);
$lang=OC_PREFERENCES::getValue( $_SESSION['user_id'], 'core', 'lang', 'en' );
$lang=OC_PREFERENCES::getValue( OC_USER::getUser(), 'core', 'lang', 'en' );
$languages=OC_L10N::findAvailableLanguages();
//put the current language in the front
unset($languages[array_search($lang,$languages)]);