Details | 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 | |||
730 | daniel-mar | 26 | abstract class OIDplusAuthContentStore extends OIDplusBaseClass implements OIDplusGetterSetterInterface { |
566 | daniel-mar | 27 | |
28 | // Getter / Setter |
||
29 | |||
1116 | daniel-mar | 30 | /** |
31 | * @param string $name |
||
32 | * @param mixed|null $default |
||
33 | * @return mixed|null |
||
34 | */ |
||
35 | public abstract function getValue(string $name, $default = NULL); |
||
566 | daniel-mar | 36 | |
1116 | daniel-mar | 37 | /** |
38 | * @param string $name |
||
39 | * @param mixed $value |
||
40 | * @return void |
||
41 | */ |
||
42 | public abstract function setValue(string $name, $value); |
||
566 | daniel-mar | 43 | |
1116 | daniel-mar | 44 | /** |
45 | * @param string $name |
||
46 | * @return bool |
||
47 | */ |
||
48 | public abstract function exists(string $name): bool; |
||
569 | daniel-mar | 49 | |
1116 | daniel-mar | 50 | /** |
51 | * @param string $name |
||
52 | * @return void |
||
53 | */ |
||
54 | public abstract function delete(string $name); |
||
569 | daniel-mar | 55 | |
1116 | daniel-mar | 56 | /** |
57 | * @return OIDplusAuthContentStore|null |
||
58 | * @throws OIDplusException |
||
59 | */ |
||
60 | public abstract static function getActiveProvider()/*: ?OIDplusAuthContentStore*/; |
||
566 | daniel-mar | 61 | |
1116 | daniel-mar | 62 | /** |
63 | * @return mixed |
||
64 | */ |
||
585 | daniel-mar | 65 | public abstract function destroySession(); |
566 | daniel-mar | 66 | |
1116 | daniel-mar | 67 | /** |
68 | * @return mixed |
||
69 | */ |
||
585 | daniel-mar | 70 | public abstract function activate(); |
71 | |||
1116 | daniel-mar | 72 | /** |
73 | * @param string $email |
||
74 | * @param string $loginfo |
||
75 | * @return void |
||
76 | */ |
||
77 | public abstract function raLoginEx(string $email, string &$loginfo); |
||
585 | daniel-mar | 78 | |
1116 | daniel-mar | 79 | /** |
80 | * @param string $email |
||
81 | * @param string $loginfo |
||
82 | * @return void |
||
83 | */ |
||
84 | public abstract function raLogoutEx(string $email, string &$loginfo); |
||
585 | daniel-mar | 85 | |
1116 | daniel-mar | 86 | /** |
87 | * @param string $loginfo |
||
88 | * @return void |
||
89 | */ |
||
90 | public abstract function adminLoginEx(string &$loginfo); |
||
585 | daniel-mar | 91 | |
1116 | daniel-mar | 92 | /** |
93 | * @param string $loginfo |
||
94 | * @return void |
||
95 | */ |
||
96 | public abstract function adminLogoutEx(string &$loginfo); |
||
585 | daniel-mar | 97 | |
98 | // RA authentication functions (low-level) |
||
99 | |||
1116 | daniel-mar | 100 | /** |
101 | * @param string $email |
||
102 | * @return void |
||
103 | */ |
||
104 | public function raLogin(string $email) { |
||
566 | daniel-mar | 105 | if (strpos($email, '|') !== false) return; |
106 | |||
585 | daniel-mar | 107 | $list = $this->getValue('oidplus_ra_logged_in'); |
566 | daniel-mar | 108 | if (is_null($list)) $list = ''; |
109 | |||
110 | $ary = ($list == '') ? array() : explode('|', $list); |
||
111 | if (!in_array($email, $ary)) $ary[] = $email; |
||
112 | $list = implode('|', $ary); |
||
113 | |||
585 | daniel-mar | 114 | $this->setValue('oidplus_ra_logged_in', $list); |
566 | daniel-mar | 115 | } |
116 | |||
1116 | daniel-mar | 117 | /** |
118 | * @param string $email |
||
119 | * @return void |
||
120 | */ |
||
121 | public function raLogout(string $email) { |
||
585 | daniel-mar | 122 | $list = $this->getValue('oidplus_ra_logged_in'); |
566 | daniel-mar | 123 | if (is_null($list)) $list = ''; |
124 | |||
125 | $ary = ($list == '') ? array() : explode('|', $list); |
||
126 | $key = array_search($email, $ary); |
||
127 | if ($key !== false) unset($ary[$key]); |
||
128 | $list = implode('|', $ary); |
||
129 | |||
585 | daniel-mar | 130 | $this->setValue('oidplus_ra_logged_in', $list); |
566 | daniel-mar | 131 | } |
132 | |||
1116 | daniel-mar | 133 | /** |
134 | * @return int |
||
135 | */ |
||
136 | public function raNumLoggedIn(): int { |
||
585 | daniel-mar | 137 | return count($this->loggedInRaList()); |
566 | daniel-mar | 138 | } |
139 | |||
1116 | daniel-mar | 140 | /** |
141 | * @return OIDplusRA[] |
||
142 | */ |
||
143 | public function loggedInRaList(): array { |
||
585 | daniel-mar | 144 | $list = $this->getValue('oidplus_ra_logged_in'); |
566 | daniel-mar | 145 | if (is_null($list)) $list = ''; |
146 | |||
147 | $res = array(); |
||
148 | foreach (array_unique(explode('|',$list)) as $ra_email) { |
||
149 | if ($ra_email == '') continue; |
||
150 | $res[] = new OIDplusRA($ra_email); |
||
151 | } |
||
152 | return $res; |
||
153 | } |
||
154 | |||
1116 | daniel-mar | 155 | /** |
156 | * @param string $email |
||
157 | * @return bool |
||
158 | */ |
||
1130 | daniel-mar | 159 | public function isRaLoggedIn(string $email): bool { |
585 | daniel-mar | 160 | foreach ($this->loggedInRaList() as $ra) { |
566 | daniel-mar | 161 | if ($email == $ra->raEmail()) return true; |
162 | } |
||
163 | return false; |
||
164 | } |
||
165 | |||
585 | daniel-mar | 166 | // Admin authentication functions (low-level) |
566 | daniel-mar | 167 | |
1116 | daniel-mar | 168 | /** |
169 | * @return void |
||
170 | */ |
||
566 | daniel-mar | 171 | public function adminLogin() { |
570 | daniel-mar | 172 | $this->setValue('oidplus_admin_logged_in', 1); |
566 | daniel-mar | 173 | } |
174 | |||
1116 | daniel-mar | 175 | /** |
176 | * @return void |
||
177 | */ |
||
566 | daniel-mar | 178 | public function adminLogout() { |
570 | daniel-mar | 179 | $this->setValue('oidplus_admin_logged_in', 0); |
566 | daniel-mar | 180 | } |
181 | |||
1116 | daniel-mar | 182 | /** |
183 | * @return bool |
||
184 | */ |
||
185 | public function isAdminLoggedIn(): bool { |
||
1301 | daniel-mar | 186 | return $this->getValue('oidplus_admin_logged_in', 0) == 1; |
566 | daniel-mar | 187 | } |
188 | |||
189 | } |