Subversion Repositories oidplus

Rev

Rev 1086 | 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
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
566 daniel-mar 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
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
566 daniel-mar 26
class OIDplusAuthContentStoreSession extends OIDplusAuthContentStore {
27
 
1116 daniel-mar 28
        /**
29
         * @return OIDplusSessionHandler
30
         */
31
        protected static function getSessionHandler(): OIDplusSessionHandler {
567 daniel-mar 32
                static $sesHandler = null;
33
                if (is_null($sesHandler)) {
34
                        $sesHandler = new OIDplusSessionHandler();
35
                }
36
                return $sesHandler;
37
        }
38
 
566 daniel-mar 39
        // Override abstract functions
585 daniel-mar 40
        # TODO: shouldn't we just include OIDplusSessionHandler in this class?
566 daniel-mar 41
 
1116 daniel-mar 42
        /**
43
         * @param string $name
44
         * @param mixed|null $default
45
         * @return mixed|null
46
         * @throws OIDplusException
47
         */
48
        public function getValue(string $name, $default = NULL) {
716 daniel-mar 49
                try {
50
                        return self::getSessionHandler()->getValue($name, $default);
1050 daniel-mar 51
                } catch (\Exception $e) {
716 daniel-mar 52
                        self::getSessionHandler()->destroySession();
847 daniel-mar 53
                        // TODO: For some reason If destroySession() is called, we won't get this Exception?!
716 daniel-mar 54
                        throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage()));
55
                }
566 daniel-mar 56
        }
57
 
1116 daniel-mar 58
        /**
59
         * @param string $name
60
         * @param mixed $value
61
         * @return void
62
         * @throws OIDplusException
63
         */
64
        public function setValue(string $name, $value) {
65
                self::getSessionHandler()->setValue($name, $value);
566 daniel-mar 66
        }
67
 
1116 daniel-mar 68
        /**
69
         * @param string $name
70
         * @return bool
71
         * @throws OIDplusException
72
         */
73
        public function exists(string $name): bool {
585 daniel-mar 74
                return self::getSessionHandler()->exists($name);
569 daniel-mar 75
        }
76
 
1116 daniel-mar 77
        /**
78
         * @param string $name
79
         * @return void
80
         * @throws OIDplusException
81
         */
82
        public function delete(string $name) {
83
                self::getSessionHandler()->delete($name);
569 daniel-mar 84
        }
85
 
1116 daniel-mar 86
        /**
87
         * @return void
88
         * @throws OIDplusException
89
         */
585 daniel-mar 90
        public function destroySession() {
1116 daniel-mar 91
                self::getSessionHandler()->destroySession();
566 daniel-mar 92
        }
93
 
1116 daniel-mar 94
        /**
95
         * @return OIDplusAuthContentStoreSession|null
96
         */
97
        public static function getActiveProvider()/*: ?OIDplusAuthContentStore*/ {
585 daniel-mar 98
                static $contentProvider = null;
99
 
100
                if (!$contentProvider) {
101
                        if (self::getSessionHandler()->isActive()) {
102
                                $contentProvider = new OIDplusAuthContentStoreSession();
103
                        }
104
                }
105
 
106
                return $contentProvider;
107
        }
108
 
1116 daniel-mar 109
        /**
110
         * @param string $email
111
         * @param string $loginfo
112
         * @return void
113
         */
114
        public function raLoginEx(string $email, string &$loginfo) {
585 daniel-mar 115
                $this->raLogin($email);
116
                if (is_null(self::getActiveProvider())) {
117
                        $loginfo = 'into new PHP session';
118
                } else {
119
                        $loginfo = 'into existing PHP session';
120
                }
121
        }
122
 
1116 daniel-mar 123
        /**
124
         * @param string $loginfo
125
         * @return void
126
         */
127
        public function adminLoginEx(string &$loginfo) {
585 daniel-mar 128
                $this->adminLogin();
129
                if (is_null(self::getActiveProvider())) {
130
                        $loginfo = 'into new PHP session';
131
                } else {
132
                        $loginfo = 'into existing PHP session';
133
                }
134
        }
135
 
1116 daniel-mar 136
        /**
137
         * @param string $email
138
         * @param string $loginfo
139
         * @return void
140
         */
141
        public function raLogoutEx(string $email, string &$loginfo) {
585 daniel-mar 142
                $this->raLogout($email);
143
                $loginfo = 'from PHP session';
144
        }
145
 
1116 daniel-mar 146
        /**
147
         * @param string $loginfo
148
         * @return void
149
         */
150
        public function adminLogoutEx(string &$loginfo) {
585 daniel-mar 151
                $this->adminLogout();
152
                $loginfo = 'from PHP session';
153
        }
154
 
1116 daniel-mar 155
        /**
156
         * @return void
157
         */
585 daniel-mar 158
        public function activate() {
159
                # Sessions automatically activate during setValue()
160
        }
161
 
569 daniel-mar 162
}