Go to most recent revision | Details | 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 | abstract class OIDplusAuthContentStore { |
||
23 | |||
24 | protected $content = array(); |
||
25 | |||
26 | // Getter / Setter |
||
27 | |||
28 | public abstract function getValue($name); |
||
29 | |||
30 | public abstract function setValue($name, $value); |
||
31 | |||
32 | protected abstract function destroySession(); |
||
33 | |||
34 | // RA authentication functions |
||
35 | |||
36 | public function raLogin($email) { |
||
37 | if (strpos($email, '|') !== false) return; |
||
38 | |||
39 | $list = $this->getValue('oidplus_logged_in'); |
||
40 | if (is_null($list)) $list = ''; |
||
41 | |||
42 | $ary = ($list == '') ? array() : explode('|', $list); |
||
43 | if (!in_array($email, $ary)) $ary[] = $email; |
||
44 | $list = implode('|', $ary); |
||
45 | |||
46 | $this->setValue('oidplus_logged_in', $list); |
||
47 | } |
||
48 | |||
49 | public function raLogout($email) { |
||
50 | $list = $this->getValue('oidplus_logged_in'); |
||
51 | if (is_null($list)) $list = ''; |
||
52 | |||
53 | $ary = ($list == '') ? array() : explode('|', $list); |
||
54 | $key = array_search($email, $ary); |
||
55 | if ($key !== false) unset($ary[$key]); |
||
56 | $list = implode('|', $ary); |
||
57 | |||
58 | $this->setValue('oidplus_logged_in', $list); |
||
59 | |||
60 | if (($list == '') && (!self::isAdminLoggedIn())) { |
||
61 | // Nobody logged in anymore. Destroy session cookie to make GDPR people happy |
||
62 | $this->destroySession(); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public function raNumLoggedIn() { |
||
67 | return count(self::loggedInRaList()); |
||
68 | } |
||
69 | |||
70 | public function raLogoutAll() { |
||
71 | $this->setValue('oidplus_logged_in', ''); |
||
72 | } |
||
73 | |||
74 | public function loggedInRaList() { |
||
75 | if (OIDplus::authUtils()->forceAllLoggedOut()) { |
||
76 | return array(); |
||
77 | } |
||
78 | |||
79 | $list = $this->getValue('oidplus_logged_in'); |
||
80 | if (is_null($list)) $list = ''; |
||
81 | |||
82 | $res = array(); |
||
83 | foreach (array_unique(explode('|',$list)) as $ra_email) { |
||
84 | if ($ra_email == '') continue; |
||
85 | $res[] = new OIDplusRA($ra_email); |
||
86 | } |
||
87 | return $res; |
||
88 | } |
||
89 | |||
90 | public function isRaLoggedIn($email) { |
||
91 | foreach (self::loggedInRaList() as $ra) { |
||
92 | if ($email == $ra->raEmail()) return true; |
||
93 | } |
||
94 | return false; |
||
95 | } |
||
96 | |||
97 | // Admin authentication functions |
||
98 | |||
99 | public function adminLogin() { |
||
100 | $this->setValue('oidplus_admin_logged_in', '1'); |
||
101 | } |
||
102 | |||
103 | public function adminLogout() { |
||
104 | $this->setValue('oidplus_admin_logged_in', '0'); |
||
105 | |||
106 | if (self::raNumLoggedIn() == 0) { |
||
107 | // Nobody logged in anymore. Destroy session cookie to make GDPR people happy |
||
108 | $this->destroySession(); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | public function isAdminLoggedIn() { |
||
113 | if (OIDplus::authUtils()->forceAllLoggedOut()) { |
||
114 | return false; |
||
115 | } |
||
116 | return $this->getValue('oidplus_admin_logged_in') == '1'; |
||
117 | } |
||
118 | |||
119 | } |