Subversion Repositories oidplus

Rev

Rev 585 | 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
 
20
if (!defined('INSIDE_OIDPLUS')) die();
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);
38
                } catch (Exception $e) {
39
                        self::getSessionHandler()->destroySession();
40
                        throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage()));
41
                }
566 daniel-mar 42
        }
43
 
569 daniel-mar 44
        public function setValue($name, $value) {
585 daniel-mar 45
                return self::getSessionHandler()->setValue($name, $value);
566 daniel-mar 46
        }
47
 
569 daniel-mar 48
        public function exists($name) {
585 daniel-mar 49
                return self::getSessionHandler()->exists($name);
569 daniel-mar 50
        }
51
 
52
        public function delete($name) {
585 daniel-mar 53
                return self::getSessionHandler()->delete($name);
569 daniel-mar 54
        }
55
 
585 daniel-mar 56
        public function destroySession() {
57
                return self::getSessionHandler()->destroySession();
566 daniel-mar 58
        }
59
 
585 daniel-mar 60
        public static function getActiveProvider() {
61
                static $contentProvider = null;
62
 
63
                if (!$contentProvider) {
64
                        if (self::getSessionHandler()->isActive()) {
65
                                $contentProvider = new OIDplusAuthContentStoreSession();
66
                        }
67
                }
68
 
69
                return $contentProvider;
70
        }
71
 
72
        public function raLoginEx($email, &$loginfo) {
73
                $this->raLogin($email);
74
                if (is_null(self::getActiveProvider())) {
75
                        $loginfo = 'into new PHP session';
76
                } else {
77
                        $loginfo = 'into existing PHP session';
78
                }
79
        }
80
 
81
        public function adminLoginEx(&$loginfo) {
82
                $this->adminLogin();
83
                if (is_null(self::getActiveProvider())) {
84
                        $loginfo = 'into new PHP session';
85
                } else {
86
                        $loginfo = 'into existing PHP session';
87
                }
88
        }
89
 
90
        public function raLogoutEx($email, &$loginfo) {
91
                $this->raLogout($email);
92
                $loginfo = 'from PHP session';
93
        }
94
 
95
        public function adminLogoutEx(&$loginfo) {
96
                $this->adminLogout();
97
                $loginfo = 'from PHP session';
98
        }
99
 
100
        public function activate() {
101
                # Sessions automatically activate during setValue()
102
                return;
103
        }
104
 
569 daniel-mar 105
}