]> git.mxchange.org Git - friendica.git/commitdiff
New function "isAuthenticated"
authorMichael <heluecht@pirati.ca>
Sat, 28 Sep 2019 18:09:11 +0000 (18:09 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 28 Sep 2019 18:09:11 +0000 (18:09 +0000)
26 files changed:
include/conversation.php
include/items.php
mod/cal.php
mod/community.php
mod/dfrn_poll.php
mod/dfrn_request.php
mod/display.php
mod/hcard.php
mod/item.php
mod/photos.php
mod/redir.php
mod/search.php
mod/subthread.php
mod/tagger.php
mod/videos.php
src/Content/Nav.php
src/Core/ACL.php
src/Core/Session.php
src/Model/Contact.php
src/Model/Item.php
src/Model/Profile.php
src/Module/Directory.php
src/Module/Like.php
src/Module/Profile/Contacts.php
src/Object/Post.php
src/Util/Security.php

index 66b6d2a11cc48cb6de5862c534f34406b706c8ec..74c8a6d27243ef9a6ac09361707783a2d26f3abd 100644 (file)
@@ -365,7 +365,7 @@ function localize_item(&$item)
                'network' => $item['author-network'], 'url' => $item['author-link']];
 
        // Only create a redirection to a magic link when logged in
-       if (!empty($item['plink']) && (local_user() || remote_user())) {
+       if (!empty($item['plink']) && Session::isAuthenticated()) {
                $item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
        }
 }
index ae686a32d9687070cb43732f458865f5ccf60551..4cc10e628cd50ec95f56884f2c4b6e58f856e50e 100644 (file)
@@ -327,7 +327,7 @@ function drop_items(array $items)
 {
        $uid = 0;
 
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return;
        }
 
index 70667707030b1bba589e389804c8ddf3864d7b25..eba8d975865b2728a114b8981be0035375d8216b 100644 (file)
@@ -27,7 +27,7 @@ use Friendica\Util\Temporal;
 
 function cal_init(App $a)
 {
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
        }
 
index 3cafced5426469192c3fbfa3d4260e461fcb4f32..d29fa729ddf4d109c6c5403954b1547b2722d8f1 100644 (file)
@@ -29,7 +29,7 @@ function community_content(App $a, $update = 0)
 {
        $o = '';
 
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                notice(L10n::t('Public access denied.') . EOL);
                return;
        }
index fa0cf1037eafe359bd16b935737f3a723617b373..031fdb28383540e97c8145a467298e51e4e7392c 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\Module\Login;
 use Friendica\Protocol\DFRN;
@@ -49,7 +50,7 @@ function dfrn_poll_init(App $a)
        $hidewall = false;
 
        if (($dfrn_id === '') && empty($_POST['dfrn_id'])) {
-               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+               if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                        throw new \Friendica\Network\HTTPException\ForbiddenException();
                }
 
index 19879c21bb334ddc35d94b98505cee1bd2e6f3c6..f78da7fb04d70a40c5b841de3d2b82c5edf5da75 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
@@ -592,7 +593,7 @@ function dfrn_request_content(App $a)
                exit();
        } else {
                // Normal web request. Display our user's introduction form.
-               if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
+               if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                        if (!Config::get('system', 'local_block')) {
                                notice(L10n::t('Public access denied.') . EOL);
                                return;
index 8d13db46fffed62cae993fee1a11e72f86e17179..0cb00434b04ba274b14b263275480e1c1159690c 100644 (file)
@@ -32,7 +32,7 @@ function display_init(App $a)
                Objects::rawContent();
        }
 
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                return;
        }
 
@@ -196,7 +196,7 @@ function display_fetchauthor($a, $item)
 
 function display_content(App $a, $update = false, $update_uid = 0)
 {
-       if (Config::get('system','block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system','block_public') && !Session::isAuthenticated()) {
                throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
        }
 
index 828eeaf0910a3fdd5338d529eb49fbc6bb51283e..ad84e24e545dd506911edf9ce7fc78adc689c7fa 100644 (file)
@@ -6,13 +6,14 @@ use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
 
 function hcard_init(App $a)
 {
-       $blocked = Config::get('system', 'block_public') && !local_user() && !remote_user();
+       $blocked = Config::get('system', 'block_public') && !Session::isAuthenticated();
 
        if ($a->argc > 1) {
                $which = $a->argv[1];
index b059f63d1fe20ba890cd1c7691ad7df065bbfb4f..28f393ac602fcb51736a8d4a4b125551bb5993f6 100644 (file)
@@ -25,6 +25,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Attach;
@@ -45,7 +46,7 @@ use Friendica\Worker\Delivery;
 require_once 'include/items.php';
 
 function item_post(App $a) {
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return 0;
        }
 
@@ -860,7 +861,7 @@ function item_post_return($baseurl, $api_source, $return_path)
 
 function item_content(App $a)
 {
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return;
        }
 
index 1514458717b415b9ba410ff395cdce3f9204edde..84be1c8285d0f0080bbdbe1e71470379c1e226c2 100644 (file)
@@ -36,7 +36,7 @@ use Friendica\Util\XML;
 
 function photos_init(App $a) {
 
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                return;
        }
 
@@ -70,7 +70,7 @@ function photos_init(App $a) {
 
                $albums = Photo::getAlbums($a->data['user']['uid']);
 
-               $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
+               $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
 
                // add various encodings to the array so we can just loop through and pick them out in a template
                $ret = ['success' => false];
@@ -829,7 +829,7 @@ function photos_content(App $a)
        // photos/name/image/xxxxx/edit
        // photos/name/image/xxxxx/drop
 
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                notice(L10n::t('Public access denied.') . EOL);
                return;
        }
index 5345b1d81b364fdfbb99ab1e9d268047d745bf62..5eeeaa681cdc6905adbdd49f2002ac8e03a30e58 100644 (file)
@@ -35,7 +35,7 @@ function redir_init(App $a) {
 
                $contact_url = $contact['url'];
 
-               if ((!local_user() && !remote_user()) // Visitors (not logged in or not remotes) can't authenticate.
+               if (!Session::isAuthenticated() // Visitors (not logged in or not remotes) can't authenticate.
                        || (!empty($a->contact['id']) && $a->contact['id'] == $cid)) // Local user is already authenticated.
                {
                        $a->redirect(defaults($url, $contact_url));
@@ -74,17 +74,8 @@ function redir_init(App $a) {
                        }
                }
 
-               // When the remote page does support OWA, then we enforce the use of it
-               $basepath = Contact::getBasepath($contact_url);
-               if (Strings::compareLink($basepath, System::baseUrl())) {
-                       $use_magic = true;
-               } else {
-                       $serverret = Network::curl($basepath . '/magic');
-                       $use_magic = $serverret->isSuccess();
-               }
-
                // Doing remote auth with dfrn.
-               if (local_user() && !$use_magic && (!empty($contact['dfrn-id']) || !empty($contact['issued-id'])) && empty($contact['pending'])) {
+               if (local_user() && (!empty($contact['dfrn-id']) || !empty($contact['issued-id'])) && empty($contact['pending'])) {
                        $dfrn_id = $orig_id = (($contact['issued-id']) ? $contact['issued-id'] : $contact['dfrn-id']);
 
                        if ($contact['duplex'] && $contact['issued-id']) {
index 4a911b4fd9828a51aaf05459bdad0dfc67174c15..9ac59502241ae903916d7ca9b873627e89277c33 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
+use Friendica\Core\Session;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
@@ -83,18 +84,18 @@ function search_init(App $a) {
 }
 
 function search_content(App $a) {
-       if (Config::get('system','block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system','block_public') && !Session::isAuthenticated()) {
                notice(L10n::t('Public access denied.') . EOL);
                return;
        }
 
-       if (Config::get('system','local_search') && !local_user() && !remote_user()) {
+       if (Config::get('system','local_search') && !Session::isAuthenticated()) {
                $e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a search."));
                $e->httpdesc = L10n::t("Public access denied.");
                throw $e;
        }
 
-       if (Config::get('system','permit_crawling') && !local_user() && !remote_user()) {
+       if (Config::get('system','permit_crawling') && !Session::isAuthenticated()) {
                // Default values:
                // 10 requests are "free", after the 11th only a call per minute is allowed
 
index 9fa1a410d37130eff5ad646e84f840c0c1011ba5..29d3f5e06eedda6f0cc34f863d78b743233ff171 100644 (file)
@@ -15,7 +15,7 @@ use Friendica\Util\XML;
 
 function subthread_content(App $a) {
 
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return;
        }
 
index 2c15cdd28c68d62f4d836b905713d1c30b435fa7..bc8b712970680761a748519e3207281b7a32fb43 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
@@ -16,7 +17,7 @@ use Friendica\Worker\Delivery;
 
 function tagger_content(App $a) {
 
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return;
        }
 
index fd40e79c90dcf6c390b18620315ff0d06c7dbe58..48027a603e9450711b8b89d1dea4303740c1f58c 100644 (file)
@@ -23,7 +23,7 @@ use Friendica\Util\Security;
 
 function videos_init(App $a)
 {
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                return;
        }
 
@@ -111,7 +111,7 @@ function videos_content(App $a)
        // videos/name/video/xxxxx/edit
 
 
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                notice(L10n::t('Public access denied.') . EOL);
                return;
        }
index ea5c0bbc05230c77984392b5171f1f2846383825..8140c5f3c13780a77da77160e95a264b7b4c86ef 100644 (file)
@@ -149,7 +149,7 @@ class Nav
                $nav['usermenu'] = [];
                $userinfo = null;
 
-               if (local_user() || remote_user()) {
+               if (Session::isAuthenticated()) {
                        $nav['logout'] = ['logout', L10n::t('Logout'), '', L10n::t('End this session')];
                } else {
                        $nav['login'] = ['login', L10n::t('Login'), ($a->module == 'login' ? 'selected' : ''), L10n::t('Sign in')];
@@ -182,7 +182,7 @@ class Nav
                        $nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')];
                }
 
-               if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !local_user() && !remote_user()) {
+               if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !Session::isAuthenticated()) {
                        $nav['register'] = ['register', L10n::t('Register'), '', L10n::t('Create an account')];
                }
 
index 6d9a95a72525cbefb7c4c690086a34fe80558131..55c174d96b51563e8b50cdf6fd9c8b231e17da2e 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Content\Feature;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
+use Friendica\Core\Session;
 use Friendica\Util\Network;
 
 /**
@@ -333,7 +334,7 @@ class ACL extends BaseObject
         */
        public static function contactAutocomplete($search, $mode, int $page = 1)
        {
-               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+               if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                        return [];
                }
 
index db455d3a2592cb2bfbbb41342d4e7d2d467f4430..b44ff3e2ea2fa928a69c4213b63c3339a20c4303 100644 (file)
@@ -53,7 +53,7 @@ class Session
 
        /**
         * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy.
-        * 
+        *
         * Handle the case where session_start() hasn't been called and the super global isn't available.
         *
         * @param string $name
@@ -255,4 +255,18 @@ class Session
                }
                DBA::close($remote_contacts);
        }
+
+       /**
+        * Returns if the current visitor is authenticated
+        *
+        * @return boolean "true" when visitor is either a local or remote user
+        */
+       public static function isAuthenticated()
+       {
+               if (empty($_SESSION['authenticated'])) {
+                       return false;
+               }
+
+               return $_SESSION['authenticated'];
+       }
 }
index 1e3d0b9154e1e537e808d46d744395e81ce9ee37..816c2a18644827ae03153c71c6d3ec4b7f282189 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Network\Probe;
@@ -2679,7 +2680,7 @@ class Contact extends BaseObject
         */
        public static function magicLink($contact_url, $url = '')
        {
-               if (!local_user() && !remote_user()) {
+               if (!Session::isAuthenticated()) {
                        return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
                }
 
@@ -2725,7 +2726,7 @@ class Contact extends BaseObject
        {
                $destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
 
-               if ((!local_user() && !remote_user()) || ($contact['network'] != Protocol::DFRN)) {
+               if (!Session::isAuthenticated() || ($contact['network'] != Protocol::DFRN)) {
                        return $destination;
                }
 
index 8e138c0cb3063d84c0ac9562d1d279465d2e8e52..c73ea99b1bfb3d863207f1827253fb6ad59ec7c4 100644 (file)
@@ -3029,7 +3029,7 @@ class Item extends BaseObject
         */
        public static function performLike($item_id, $verb)
        {
-               if (!local_user() && !remote_user()) {
+               if (!Session::isAuthenticated()) {
                        return false;
                }
 
@@ -3428,7 +3428,7 @@ class Item extends BaseObject
                }
 
                // Update the cached values if there is no "zrl=..." on the links.
-               $update = (!local_user() && !remote_user() && ($item["uid"] == 0));
+               $update = (!Session::isAuthenticated() && ($item["uid"] == 0));
 
                // Or update it if the current viewer is the intented viewer.
                if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
index bdb69750dc9cdea5b7022f1dc83869a70d077449..01c585139238678a62c52f6ec4771fae3ae17929 100644 (file)
@@ -215,7 +215,7 @@ class Profile
                        );
                }
 
-               $block = ((Config::get('system', 'block_public') && !local_user() && !remote_user()) ? true : false);
+               $block = ((Config::get('system', 'block_public') && !Session::isAuthenticated()) ? true : false);
 
                /**
                 * @todo
@@ -448,7 +448,7 @@ class Profile
                $about    = !empty($profile['about'])    ? L10n::t('About:')    : false;
                $xmpp     = !empty($profile['xmpp'])     ? L10n::t('XMPP:')     : false;
 
-               if ((!empty($profile['hidewall']) || $block) && !local_user() && !remote_user()) {
+               if ((!empty($profile['hidewall']) || $block) && !Session::isAuthenticated()) {
                        $location = $gender = $marital = $homepage = $about = false;
                }
 
index 4674a9f8575548fd7f73ad3aa4a9b43e287de146..7d75e4d477aa0f7cfa4ea5b2601b1074122d433a 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Content\Pager;
 use Friendica\Content\Widget;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Session;
 use Friendica\Core\Renderer;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
@@ -25,8 +26,8 @@ class Directory extends BaseModule
                $app = self::getApp();
                $config = $app->getConfig();
 
-               if (($config->get('system', 'block_public') && !local_user() && !remote_user()) ||
-                       ($config->get('system', 'block_local_dir') && !local_user() && !remote_user())) {
+               if (($config->get('system', 'block_public') && !Session::isAuthenticated()) ||
+                       ($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) {
                        throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
                }
 
index f57cbadfd357516abe30977c63f3d6faf4a74484..a43e38045c8c611213a81ba7b240ebd2a98603c9 100644 (file)
@@ -4,6 +4,7 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Model\Item;
+use Friendica\Core\Session;
 use Friendica\Network\HTTPException;
 use Friendica\Util\Strings;
 
@@ -14,7 +15,7 @@ class Like extends BaseModule
 {
        public static function rawContent()
        {
-               if (!local_user() && !remote_user()) {
+               if (!Session::isAuthenticated()) {
                        throw new HTTPException\ForbiddenException();
                }
 
index 7463d4043f8565d453dc6c2b2929a3fcb73bad5e..ed41f421b12a8dec7c81de7d4458bbd08e9e5f04 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
+use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
@@ -19,7 +20,7 @@ class Contacts extends BaseModule
 {
        public static function content()
        {
-               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+               if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
                        throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
                }
 
index afb55a0212ca37606bb3843461a11c7edb1e3ea0..2ef53d075ce1c467770539a3a145a569ced16803 100644 (file)
@@ -219,7 +219,7 @@ class Post extends BaseObject
                $author = ['uid' => 0, 'id' => $item['author-id'],
                        'network' => $item['author-network'], 'url' => $item['author-link']];
 
-               if (local_user() || remote_user()) {
+               if (Session::isAuthenticated()) {
                        $profile_link = Contact::magicLinkByContact($author);
                } else {
                        $profile_link = $item['author-link'];
index 1d7162ab8e9c59308fe26e2c727e2f22fafa14f5..043c59d84f20a0fd1ed1023dd48dcd1ff9829017 100644 (file)
@@ -21,7 +21,7 @@ class Security extends BaseObject
        {
                static $verified = 0;
 
-               if (!local_user() && !remote_user()) {
+               if (!Session::isAuthenticated()) {
                        return false;
                }