Rev 847 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
566 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
566 | daniel-mar | 21 | |
22 | class OIDplusAuthContentStoreSession extends OIDplusAuthContentStore { |
||
23 | |||
585 | daniel-mar | 24 | protected static function getSessionHandler() { |
567 | daniel-mar | 25 | static $sesHandler = null; |
26 | if (is_null($sesHandler)) { |
||
27 | $sesHandler = new OIDplusSessionHandler(); |
||
28 | } |
||
29 | return $sesHandler; |
||
30 | } |
||
31 | |||
566 | daniel-mar | 32 | // Override abstract functions |
585 | daniel-mar | 33 | # TODO: shouldn't we just include OIDplusSessionHandler in this class? |
566 | daniel-mar | 34 | |
569 | daniel-mar | 35 | public function getValue($name, $default = NULL) { |
716 | daniel-mar | 36 | try { |
37 | return self::getSessionHandler()->getValue($name, $default); |
||
1050 | daniel-mar | 38 | } catch (\Exception $e) { |
716 | daniel-mar | 39 | self::getSessionHandler()->destroySession(); |
847 | daniel-mar | 40 | // TODO: For some reason If destroySession() is called, we won't get this Exception?! |
716 | daniel-mar | 41 | throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage())); |
42 | } |
||
566 | daniel-mar | 43 | } |
44 | |||
569 | daniel-mar | 45 | public function setValue($name, $value) { |
585 | daniel-mar | 46 | return self::getSessionHandler()->setValue($name, $value); |
566 | daniel-mar | 47 | } |
48 | |||
569 | daniel-mar | 49 | public function exists($name) { |
585 | daniel-mar | 50 | return self::getSessionHandler()->exists($name); |
569 | daniel-mar | 51 | } |
52 | |||
53 | public function delete($name) { |
||
585 | daniel-mar | 54 | return self::getSessionHandler()->delete($name); |
569 | daniel-mar | 55 | } |
56 | |||
585 | daniel-mar | 57 | public function destroySession() { |
58 | return self::getSessionHandler()->destroySession(); |
||
566 | daniel-mar | 59 | } |
60 | |||
585 | daniel-mar | 61 | public static function getActiveProvider() { |
62 | static $contentProvider = null; |
||
63 | |||
64 | if (!$contentProvider) { |
||
65 | if (self::getSessionHandler()->isActive()) { |
||
66 | $contentProvider = new OIDplusAuthContentStoreSession(); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | return $contentProvider; |
||
71 | } |
||
72 | |||
73 | public function raLoginEx($email, &$loginfo) { |
||
74 | $this->raLogin($email); |
||
75 | if (is_null(self::getActiveProvider())) { |
||
76 | $loginfo = 'into new PHP session'; |
||
77 | } else { |
||
78 | $loginfo = 'into existing PHP session'; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public function adminLoginEx(&$loginfo) { |
||
83 | $this->adminLogin(); |
||
84 | if (is_null(self::getActiveProvider())) { |
||
85 | $loginfo = 'into new PHP session'; |
||
86 | } else { |
||
87 | $loginfo = 'into existing PHP session'; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | public function raLogoutEx($email, &$loginfo) { |
||
92 | $this->raLogout($email); |
||
93 | $loginfo = 'from PHP session'; |
||
94 | } |
||
95 | |||
96 | public function adminLogoutEx(&$loginfo) { |
||
97 | $this->adminLogout(); |
||
98 | $loginfo = 'from PHP session'; |
||
99 | } |
||
100 | |||
101 | public function activate() { |
||
102 | # Sessions automatically activate during setValue() |
||
103 | return; |
||
104 | } |
||
105 | |||
569 | daniel-mar | 106 | } |