Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-10-16 11:33:39 +0300
committerJulius Härtl <jus@bitgrid.net>2019-12-02 14:28:30 +0300
commitbaa11f406390cca2a890c16bf1cf0b404b2fc700 (patch)
tree4e3d7eb0b39fb23650f89c56e93432041527e272 /lib/Service/SessionService.php
parent2dee8b69ce453e7bc0ebcec28cf375f7742d75d8 (diff)
Start with direct editing
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/Service/SessionService.php')
-rw-r--r--lib/Service/SessionService.php40
1 files changed, 35 insertions, 5 deletions
diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php
index b7be301ef..457fea497 100644
--- a/lib/Service/SessionService.php
+++ b/lib/Service/SessionService.php
@@ -29,6 +29,7 @@ use OCA\Text\Db\Session;
use OCA\Text\Db\SessionMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DirectEditing\IManager;
use OCP\IAvatar;
use OCP\IAvatarManager;
use OCP\Security\ISecureRandom;
@@ -40,13 +41,29 @@ class SessionService {
private $sessionMapper;
private $secureRandom;
private $timeFactory;
+ private $avatarManager;
private $userId;
- public function __construct(SessionMapper $sessionMapper, ISecureRandom $secureRandom, ITimeFactory $timeFactory, $userId) {
+ /** @var Session cache current session in the request */
+ private $session = null;
+
+ public function __construct(SessionMapper $sessionMapper, ISecureRandom $secureRandom, ITimeFactory $timeFactory, IAvatarManager $avatarManager, $userId) {
$this->sessionMapper = $sessionMapper;
$this->secureRandom = $secureRandom;
$this->timeFactory = $timeFactory;
$this->userId = $userId;
+ // FIXME
+ $token = \OC::$server->getRequest()->getParam('token');
+ if ($this->userId === null && $token !== null) {
+ $this->directManager = \OC::$server->query(IManager::class);
+ try {
+ $tokenObject = $this->directManager->getToken($token);
+ $tokenObject->extend();
+ $tokenObject->useTokenScope();
+ $this->userId = $tokenObject->getUser();
+ } catch (\Exception $e) {}
+ }
+ $this->avatarManager = $avatarManager;
}
public function initSession($documentId, $guestName = null): Session {
@@ -55,9 +72,7 @@ class SessionService {
$userName = $this->userId ? $this->userId : $guestName;
$session->setUserId($userName);
$session->setToken($this->secureRandom->generate(64));
- /** @var IAvatarManager $avatarGenerator */
- $avatarGenerator = \OC::$server->query(IAvatarManager::class);
- $color = $avatarGenerator->getGuestAvatar($userName)->avatarBackgroundColor($userName);
+ $color = $this->avatarManager->getGuestAvatar($userName)->avatarBackgroundColor($userName);
$color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b);
$session->setColor($color);
if ($this->userId === null) {
@@ -96,9 +111,24 @@ class SessionService {
return $this->sessionMapper->deleteInactive($documentId);
}
+ public function getSession($documentId, $sessionId, $token) {
+ if ($this->session !== null) {
+ return $this->session;
+ }
+ try {
+ return $this->sessionMapper->find($documentId, $sessionId, $token);
+ } catch (DoesNotExistException $e) {
+ $this->session = false;
+ return false;
+ }
+ }
+
public function isValidSession($documentId, $sessionId, $token) {
+ if ($this->userId) {
+ return true;
+ }
try {
- $session = $this->sessionMapper->find($documentId, $sessionId, $token);
+ $session = $this->getSession($documentId, $sessionId, $token);
} catch (DoesNotExistException $e) {
return false;
}