MCPcopy Create free account
hub / github.com/Rello/analytics / DataSession

Class DataSession

lib/DataSession.php:14–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12use OCP\ISession;
13
14class DataSession
15{
16 /** @var ISession */
17 protected $session;
18
19 public function __construct(ISession $session)
20 {
21 $this->session = $session;
22 }
23
24 public function isShareAuthenticated(string $token, string $passwordHash): bool
25 {
26 $this->removeLegacyPassword($token);
27 $storedFingerprint = $this->getValue('analytics-share-auth', $token);
28 return $storedFingerprint !== null
29 && hash_equals($storedFingerprint, hash('sha256', $passwordHash));
30 }
31
32 protected function getValue(string $key, string $token): ?string
33 {
34 $values = $this->getValues($key);
35 if (!isset($values[$token])) {
36 return null;
37 }
38 return $values[$token];
39 }
40
41 protected function getValues(string $key): array
42 {
43 $values = $this->session->get($key);
44 if ($values === null) {
45 return [];
46 }
47 $values = json_decode($values, true);
48 if ($values === null) {
49 return [];
50 }
51 return $values;
52 }
53
54 public function setShareAuthenticated(string $token, string $passwordHash): void
55 {
56 $this->removeLegacyPassword($token);
57 $this->setValue('analytics-share-auth', $token, hash('sha256', $passwordHash));
58 }
59
60 protected function setValue(string $key, string $token, string $value): void
61 {
62 $values = $this->session->get($key);
63 if ($values === null) {
64 $values = [];
65 } else {
66 $values = json_decode($values, true);
67 if ($values === null) {
68 $values = [];
69 }
70 }
71 $values[$token] = $value;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected