From b268fa60e7c523672a64bbefede43ff89e651d5f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Mar 2023 19:00:48 -0400 Subject: [PATCH] Add explicit parameter to IHandleUserSession->setvisitorContacts - Convert some remaining $_SESSION references to object calls - Address part of https://github.com/friendica/friendica/issues/12486#issuecomment-1428489772 --- .../Session/Capability/IHandleUserSessions.php | 4 +++- src/Core/Session/Model/UserSession.php | 4 ++-- src/Model/Profile.php | 16 +++++++++------- src/Security/Authentication.php | 6 ++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Core/Session/Capability/IHandleUserSessions.php b/src/Core/Session/Capability/IHandleUserSessions.php index 507b9e042..5734eafdf 100644 --- a/src/Core/Session/Capability/IHandleUserSessions.php +++ b/src/Core/Session/Capability/IHandleUserSessions.php @@ -109,6 +109,8 @@ interface IHandleUserSessions extends IHandleSessions /** * Set the session variable that contains the contact IDs for the visitor's contact URL + * + * @param string $my_url */ - public function setVisitorsContacts(); + public function setVisitorsContacts(string $my_url); } diff --git a/src/Core/Session/Model/UserSession.php b/src/Core/Session/Model/UserSession.php index a544487bd..8dfc3d832 100644 --- a/src/Core/Session/Model/UserSession.php +++ b/src/Core/Session/Model/UserSession.php @@ -140,9 +140,9 @@ class UserSession implements IHandleUserSessions } /** {@inheritDoc} */ - public function setVisitorsContacts() + public function setVisitorsContacts(string $my_url) { - $this->session->set('remote', Contact::getVisitorByUrl($this->session->get('my_url'))); + $this->session->set('remote', Contact::getVisitorByUrl($my_url)); } /** {@inheritDoc} */ diff --git a/src/Model/Profile.php b/src/Model/Profile.php index e2857947c..e6c8e4822 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -795,14 +795,16 @@ class Profile $visitor = Contact::getById($cid); // Authenticate the visitor. - $_SESSION['authenticated'] = 1; - $_SESSION['visitor_id'] = $visitor['id']; - $_SESSION['visitor_handle'] = $visitor['addr']; - $_SESSION['visitor_home'] = $visitor['url']; - $_SESSION['my_url'] = $visitor['url']; - $_SESSION['remote_comment'] = $visitor['subscribe']; + DI::userSession()->setMultiple([ + 'authenticated' => 1, + 'visitor_id' => $visitor['id'], + 'visitor_handle' => $visitor['addr'], + 'visitor_home' => $visitor['url'], + 'my_url' => $visitor['url'], + 'remote_comment' => $visitor['subscribe'], + ]); - DI::userSession()->setVisitorsContacts(); + DI::userSession()->setVisitorsContacts($visitor['url']); $a->setContactId($visitor['id']); diff --git a/src/Security/Authentication.php b/src/Security/Authentication.php index 4db5fdfed..91963ee39 100644 --- a/src/Security/Authentication.php +++ b/src/Security/Authentication.php @@ -323,19 +323,21 @@ class Authentication */ public function setForUser(App $a, array $user_record, bool $login_initial = false, bool $interactive = false, bool $login_refresh = false) { + $my_url = $this->baseUrl . '/profile/' . $user_record['nickname']; + $this->session->setMultiple([ 'uid' => $user_record['uid'], 'theme' => $user_record['theme'], 'mobile-theme' => $this->pConfig->get($user_record['uid'], 'system', 'mobile_theme'), 'authenticated' => 1, 'page_flags' => $user_record['page-flags'], - 'my_url' => $this->baseUrl . '/profile/' . $user_record['nickname'], + 'my_url' => $my_url, 'my_address' => $user_record['nickname'] . '@' . substr($this->baseUrl, strpos($this->baseUrl, '://') + 3), 'addr' => $this->remoteAddress, 'nickname' => $user_record['nickname'], ]); - $this->session->setVisitorsContacts(); + $this->session->setVisitorsContacts($my_url); $member_since = strtotime($user_record['register_date']); $this->session->set('new_member', time() < ($member_since + (60 * 60 * 24 * 14)));