]> source.dussan.org Git - nextcloud-server.git/commitdiff
add oc_user::getUser to get the user id of the loggedin user
authorRobin Appelman <icewind1991@gmail.com>
Wed, 22 Jun 2011 10:50:57 +0000 (12:50 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Wed, 22 Jun 2011 10:50:57 +0000 (12:50 +0200)
17 files changed:
admin/ajax/changepassword.php
admin/ajax/creategroup.php
admin/ajax/createuser.php
admin/ajax/removegroup.php
admin/ajax/removeuser.php
admin/ajax/togglegroups.php
admin/apps.php
admin/system.php
admin/users.php
apps/files_publiclink/lib_public.php
files/admin.php
lib/base.php
lib/l10n.php
lib/user.php
log/index.php
settings/ajax/setlanguage.php
settings/index.php

index a8f3af1517518ed53a552afe834b641b73a260dc..51634908a7632ce881609445708d2f73a6b2aa0f 100644 (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();
 }
index eec27587930dcc0ae27a683c252d247a9c3df4ab..df9a36aaa2fa2f352566476b439f8ea0a629bb6a 100644 (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();
 }
index a6e4ec0e93d85ad1f1aabe5f56b616052a8a96a7..507ded9079f07c4ff2c0288a8cc4ff27cf609a9f 100644 (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();
 }
index c7991ba5819ca81d5b470edca56b9fc28f925f5d..e3d62e5fac8b0f552f33b214374cf02bcdf8c8ed 100644 (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();
 }
index 7e587f1605800b840535c06c395145bb6728c709..6b48146ad453d07ce3272af8e2f07a45667b90a3 100644 (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();
 }
index f821ae0bfaa61e0008850585ccef5a65b515c1a6..5c7bd393e923c3d3b9bff7385e83037433d6d120 100644 (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();
 }
index 285cf9e90f50e315f65a5b74de4ec67ac7d47cf7..b47611f536d800dc29b1b12826941362466b35de 100644 (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();
 }
index 310979295f0db24e9cd008625ec6e029f8f70e26..284509144eee97d17069958d42688a5f187722d0 100644 (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();
 }
index e44feb40fe28d0a199d045083fed5aeeea9a5b7a..0848d57162a16b8cd2d7b41c3f7403626222e614 100644 (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();
 }
index aeef9212377ad31a57f1dcf7273213d4c6a801cd..93ccc52d0e97e654af27bc2dee597485b816d9a2 100644 (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));
                }
index 59b822468ed44a2343fd90fa4806759e30c0fad6..5c9923aff865bd1ea6f90860d0efb950b0f0bfb2 100644 (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();
 }
index e93c47127275308eedff1e73800e61f3e7dcddb1..0453e272a4b72bc40b21f0472c81f07b6e828116 100644 (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
index ff0238241a6802503623639092302e2dbbf4e8d2..053c6fbc10e5966786239448cae16cb1abc4ee7c 100644 (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;
index 2e11a30e85ead4669573e8e9dfdc75f47ba378ff..7eafef924a83f71bbad0e8946da380cd13e2041f 100644 (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
index 950e1f82d1960f8931e19e63ad30990b1b13dee9..4986526e0070648599bd8b43b9c08820afee7f8c 100644 (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){
index f971806f4c6f28a0da66437078ce9f4f429e31f2..bc467fb90040ce328633048b23157c20cf27e4bc 100644 (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") )));
index e2a73a5d9f3a34d3153a67c7213bf0e84cc93a86..07adba142d6fb0713581334dc681f8702a30bdee 100644 (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)]);