Rev 1130 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1130 | Rev 1301 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | namespace ViaThinkSoft\OIDplus; |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | // phpcs:disable PSR1.Files.SideEffects |
22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | abstract class OIDplusAuthContentStore extends OIDplusBaseClass implements OIDplusGetterSetterInterface { |
26 | abstract class OIDplusAuthContentStore extends OIDplusBaseClass implements OIDplusGetterSetterInterface { |
27 | 27 | ||
28 | // Getter / Setter |
28 | // Getter / Setter |
29 | 29 | ||
30 | /** |
30 | /** |
31 | * @param string $name |
31 | * @param string $name |
32 | * @param mixed|null $default |
32 | * @param mixed|null $default |
33 | * @return mixed|null |
33 | * @return mixed|null |
34 | */ |
34 | */ |
35 | public abstract function getValue(string $name, $default = NULL); |
35 | public abstract function getValue(string $name, $default = NULL); |
36 | 36 | ||
37 | /** |
37 | /** |
38 | * @param string $name |
38 | * @param string $name |
39 | * @param mixed $value |
39 | * @param mixed $value |
40 | * @return void |
40 | * @return void |
41 | */ |
41 | */ |
42 | public abstract function setValue(string $name, $value); |
42 | public abstract function setValue(string $name, $value); |
43 | 43 | ||
44 | /** |
44 | /** |
45 | * @param string $name |
45 | * @param string $name |
46 | * @return bool |
46 | * @return bool |
47 | */ |
47 | */ |
48 | public abstract function exists(string $name): bool; |
48 | public abstract function exists(string $name): bool; |
49 | 49 | ||
50 | /** |
50 | /** |
51 | * @param string $name |
51 | * @param string $name |
52 | * @return void |
52 | * @return void |
53 | */ |
53 | */ |
54 | public abstract function delete(string $name); |
54 | public abstract function delete(string $name); |
55 | 55 | ||
56 | /** |
56 | /** |
57 | * @return OIDplusAuthContentStore|null |
57 | * @return OIDplusAuthContentStore|null |
58 | * @throws OIDplusException |
58 | * @throws OIDplusException |
59 | */ |
59 | */ |
60 | public abstract static function getActiveProvider()/*: ?OIDplusAuthContentStore*/; |
60 | public abstract static function getActiveProvider()/*: ?OIDplusAuthContentStore*/; |
61 | 61 | ||
62 | /** |
62 | /** |
63 | * @return mixed |
63 | * @return mixed |
64 | */ |
64 | */ |
65 | public abstract function destroySession(); |
65 | public abstract function destroySession(); |
66 | 66 | ||
67 | /** |
67 | /** |
68 | * @return mixed |
68 | * @return mixed |
69 | */ |
69 | */ |
70 | public abstract function activate(); |
70 | public abstract function activate(); |
71 | 71 | ||
72 | /** |
72 | /** |
73 | * @param string $email |
73 | * @param string $email |
74 | * @param string $loginfo |
74 | * @param string $loginfo |
75 | * @return void |
75 | * @return void |
76 | */ |
76 | */ |
77 | public abstract function raLoginEx(string $email, string &$loginfo); |
77 | public abstract function raLoginEx(string $email, string &$loginfo); |
78 | 78 | ||
79 | /** |
79 | /** |
80 | * @param string $email |
80 | * @param string $email |
81 | * @param string $loginfo |
81 | * @param string $loginfo |
82 | * @return void |
82 | * @return void |
83 | */ |
83 | */ |
84 | public abstract function raLogoutEx(string $email, string &$loginfo); |
84 | public abstract function raLogoutEx(string $email, string &$loginfo); |
85 | 85 | ||
86 | /** |
86 | /** |
87 | * @param string $loginfo |
87 | * @param string $loginfo |
88 | * @return void |
88 | * @return void |
89 | */ |
89 | */ |
90 | public abstract function adminLoginEx(string &$loginfo); |
90 | public abstract function adminLoginEx(string &$loginfo); |
91 | 91 | ||
92 | /** |
92 | /** |
93 | * @param string $loginfo |
93 | * @param string $loginfo |
94 | * @return void |
94 | * @return void |
95 | */ |
95 | */ |
96 | public abstract function adminLogoutEx(string &$loginfo); |
96 | public abstract function adminLogoutEx(string &$loginfo); |
97 | 97 | ||
98 | // RA authentication functions (low-level) |
98 | // RA authentication functions (low-level) |
99 | 99 | ||
100 | /** |
100 | /** |
101 | * @param string $email |
101 | * @param string $email |
102 | * @return void |
102 | * @return void |
103 | */ |
103 | */ |
104 | public function raLogin(string $email) { |
104 | public function raLogin(string $email) { |
105 | if (strpos($email, '|') !== false) return; |
105 | if (strpos($email, '|') !== false) return; |
106 | 106 | ||
107 | $list = $this->getValue('oidplus_ra_logged_in'); |
107 | $list = $this->getValue('oidplus_ra_logged_in'); |
108 | if (is_null($list)) $list = ''; |
108 | if (is_null($list)) $list = ''; |
109 | 109 | ||
110 | $ary = ($list == '') ? array() : explode('|', $list); |
110 | $ary = ($list == '') ? array() : explode('|', $list); |
111 | if (!in_array($email, $ary)) $ary[] = $email; |
111 | if (!in_array($email, $ary)) $ary[] = $email; |
112 | $list = implode('|', $ary); |
112 | $list = implode('|', $ary); |
113 | 113 | ||
114 | $this->setValue('oidplus_ra_logged_in', $list); |
114 | $this->setValue('oidplus_ra_logged_in', $list); |
115 | } |
115 | } |
116 | 116 | ||
117 | /** |
117 | /** |
118 | * @param string $email |
118 | * @param string $email |
119 | * @return void |
119 | * @return void |
120 | */ |
120 | */ |
121 | public function raLogout(string $email) { |
121 | public function raLogout(string $email) { |
122 | $list = $this->getValue('oidplus_ra_logged_in'); |
122 | $list = $this->getValue('oidplus_ra_logged_in'); |
123 | if (is_null($list)) $list = ''; |
123 | if (is_null($list)) $list = ''; |
124 | 124 | ||
125 | $ary = ($list == '') ? array() : explode('|', $list); |
125 | $ary = ($list == '') ? array() : explode('|', $list); |
126 | $key = array_search($email, $ary); |
126 | $key = array_search($email, $ary); |
127 | if ($key !== false) unset($ary[$key]); |
127 | if ($key !== false) unset($ary[$key]); |
128 | $list = implode('|', $ary); |
128 | $list = implode('|', $ary); |
129 | 129 | ||
130 | $this->setValue('oidplus_ra_logged_in', $list); |
130 | $this->setValue('oidplus_ra_logged_in', $list); |
131 | } |
131 | } |
132 | 132 | ||
133 | /** |
133 | /** |
134 | * @return int |
134 | * @return int |
135 | */ |
135 | */ |
136 | public function raNumLoggedIn(): int { |
136 | public function raNumLoggedIn(): int { |
137 | return count($this->loggedInRaList()); |
137 | return count($this->loggedInRaList()); |
138 | } |
138 | } |
139 | 139 | ||
140 | /** |
140 | /** |
141 | * @return OIDplusRA[] |
141 | * @return OIDplusRA[] |
142 | */ |
142 | */ |
143 | public function loggedInRaList(): array { |
143 | public function loggedInRaList(): array { |
144 | $list = $this->getValue('oidplus_ra_logged_in'); |
144 | $list = $this->getValue('oidplus_ra_logged_in'); |
145 | if (is_null($list)) $list = ''; |
145 | if (is_null($list)) $list = ''; |
146 | 146 | ||
147 | $res = array(); |
147 | $res = array(); |
148 | foreach (array_unique(explode('|',$list)) as $ra_email) { |
148 | foreach (array_unique(explode('|',$list)) as $ra_email) { |
149 | if ($ra_email == '') continue; |
149 | if ($ra_email == '') continue; |
150 | $res[] = new OIDplusRA($ra_email); |
150 | $res[] = new OIDplusRA($ra_email); |
151 | } |
151 | } |
152 | return $res; |
152 | return $res; |
153 | } |
153 | } |
154 | 154 | ||
155 | /** |
155 | /** |
156 | * @param string $email |
156 | * @param string $email |
157 | * @return bool |
157 | * @return bool |
158 | */ |
158 | */ |
159 | public function isRaLoggedIn(string $email): bool { |
159 | public function isRaLoggedIn(string $email): bool { |
160 | foreach ($this->loggedInRaList() as $ra) { |
160 | foreach ($this->loggedInRaList() as $ra) { |
161 | if ($email == $ra->raEmail()) return true; |
161 | if ($email == $ra->raEmail()) return true; |
162 | } |
162 | } |
163 | return false; |
163 | return false; |
164 | } |
164 | } |
165 | 165 | ||
166 | // Admin authentication functions (low-level) |
166 | // Admin authentication functions (low-level) |
167 | 167 | ||
168 | /** |
168 | /** |
169 | * @return void |
169 | * @return void |
170 | */ |
170 | */ |
171 | public function adminLogin() { |
171 | public function adminLogin() { |
172 | $this->setValue('oidplus_admin_logged_in', 1); |
172 | $this->setValue('oidplus_admin_logged_in', 1); |
173 | } |
173 | } |
174 | 174 | ||
175 | /** |
175 | /** |
176 | * @return void |
176 | * @return void |
177 | */ |
177 | */ |
178 | public function adminLogout() { |
178 | public function adminLogout() { |
179 | $this->setValue('oidplus_admin_logged_in', 0); |
179 | $this->setValue('oidplus_admin_logged_in', 0); |
180 | } |
180 | } |
181 | 181 | ||
182 | /** |
182 | /** |
183 | * @return bool |
183 | * @return bool |
184 | */ |
184 | */ |
185 | public function isAdminLoggedIn(): bool { |
185 | public function isAdminLoggedIn(): bool { |
186 | return $this->getValue('oidplus_admin_logged_in') == 1; |
186 | return $this->getValue('oidplus_admin_logged_in', 0) == 1; |
187 | } |
187 | } |
188 | 188 | ||
189 | } |
189 | } |
190 | 190 |