use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Database\Definition\DbaDefinition;
use Friendica\Database\Definition\ViewDefinition;
-use Friendica\Model\User;
use Friendica\Module\Maintenance;
use Friendica\Security\Authentication;
use Friendica\Core\Config\ValueObject\Cache;
'videoheight' => 350,
];
- private $user_id = 0;
- private $nickname = '';
private $timezone = '';
private $profile_owner = 0;
private $contact_id = 0;
private $session;
/**
- * Set the user ID
- *
- * @param int $user_id
- * @return void
- */
- public function setLoggedInUserId(int $user_id)
- {
- $this->user_id = $user_id;
- }
-
- /**
- * Set the nickname
- *
- * @param int $user_id
- * @return void
+ * @deprecated 2022.03
+ * @see IHandleUserSessions::isAuthenticated()
*/
- public function setLoggedInUserNickname(string $nickname)
- {
- $this->nickname = $nickname;
- }
-
public function isLoggedIn(): bool
{
- return $this->session->getLocalUserId() && $this->user_id && ($this->user_id == $this->session->getLocalUserId());
+ return $this->session->isAuthenticated();
}
/**
- * Check if current user has admin role.
- *
- * @return bool true if user is an admin
- * @throws Exception
+ * @deprecated 2022.03
+ * @see IHandleUserSessions::isSiteAdmin()
*/
public function isSiteAdmin(): bool
{
- return
- $this->session->getLocalUserId()
- && $this->database->exists('user', [
- 'uid' => $this->getLoggedInUserId(),
- 'email' => User::getAdminEmailList()
- ]);
+ return $this->session->isSiteAdmin();
}
/**
- * Fetch the user id
- * @return int User id
+ * @deprecated 2022.03
+ * @see IHandleUserSessions::getLocalUserId()
*/
public function getLoggedInUserId(): int
{
- return $this->user_id;
+ return $this->session->getLocalUserId();
}
/**
- * Fetch the user nick name
- * @return string User's nickname
+ * @deprecated 2022.03
+ * @see IHandleUserSessions::getLocalUserNickname()
*/
public function getLoggedInUserNickname(): string
{
- return $this->nickname;
+ return $this->session->getLocalUserNickname();
}
/**
*/
public function getLocalUserId();
+ /**
+ * Returns the user nickname of locally logged-in user.
+ *
+ * @return string|false User's nickname or false
+ */
+ public function getLocalUserNickname();
+
/**
* Returns the public contact id of logged-in user or false.
*
*/
public function isAuthenticated(): bool;
+ /**
+ * Check if current user has admin role.
+ *
+ * @return bool true if user is an admin
+ */
+ public function isSiteAdmin(): bool;
+
/**
* Returns User ID of the managed user in case it's a different identity
*
use Friendica\Core\Session\Capability\IHandleSessions;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Contact;
+use Friendica\Model\User;
/**
* This class handles user sessions, which is directly extended from regular session
return false;
}
+ /** {@inheritDoc} */
+ public function getLocalUserNickname()
+ {
+ if ($this->isAuthenticated()) {
+ return $this->session->get('nickname');
+ }
+
+ return false;
+ }
+
/** {@inheritDoc} */
public function getPublicContactId()
{
return $this->session->get('authenticated', false);
}
+ /** {@inheritDoc} */
+ public function isSiteAdmin(): bool
+ {
+ return User::isSiteAdmin($this->getLocalUserId());
+ }
+
/** {@inheritDoc} */
public function setVisitorsContacts()
{
return DBA::update('user', $fields, ['uid' => $uid]);
}
+ /**
+ * Returns if the given uid is valid and in the admin list
+ *
+ * @param int $uid
+ *
+ * @return bool
+ * @throws Exception
+ */
+ public static function isSiteAdmin(int $uid): bool
+ {
+ return DBA::exists('user', [
+ 'uid' => $uid,
+ 'email' => self::getAdminEmailList()
+ ]);
+ }
+
/**
* Checks if a nickname is in the list of the forbidden nicknames
*
}
}
- $a->setLoggedInUserId($user_record['uid']);
- $a->setLoggedInUserNickname($user_record['nickname']);
-
if ($login_initial) {
Hook::callAll('logged_in', $user_record);
}
*/
public function testApiDirectMessagesNewWithScreenName()
{
- DI::app()->setLoggedInUserNickname('selfcontact');
+ DI::session()->set('nickname', 'selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
*/
public function testApiDirectMessagesNewWithTitle()
{
- DI::app()->setLoggedInUserNickname('selfcontact');
+ DI::session()->set('nickname', 'selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());
*/
public function testApiDirectMessagesNewWithRss()
{
- DI::app()->setLoggedInUserNickname('selfcontact');
+ DI::session()->set('nickname', 'selfcontact');
$directMessage = new DirectMessage(DI::logger(), DI::dba(), DI::twitterUser());