Subversion Repositories oidplus

Rev

Rev 1050 | 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
 
730 daniel-mar 26
abstract class OIDplusAuthContentStore extends OIDplusBaseClass implements OIDplusGetterSetterInterface {
566 daniel-mar 27
 
28
        // Getter / Setter
29
 
569 daniel-mar 30
        public abstract function getValue($name, $default = NULL);
566 daniel-mar 31
 
569 daniel-mar 32
        public abstract function setValue($name, $value);
566 daniel-mar 33
 
569 daniel-mar 34
        public abstract function exists($name);
35
 
36
        public abstract function delete($name);
37
 
585 daniel-mar 38
        public abstract static function getActiveProvider();
566 daniel-mar 39
 
585 daniel-mar 40
        public abstract function destroySession();
566 daniel-mar 41
 
585 daniel-mar 42
        public abstract function activate();
43
 
44
        public abstract function raLoginEx($email, &$loginfo);
45
 
46
        public abstract function raLogoutEx($email, &$loginfo);
47
 
48
        public abstract function adminLoginEx(&$loginfo);
49
 
50
        public abstract function adminLogoutEx(&$loginfo);
51
 
52
        // RA authentication functions (low-level)
53
 
566 daniel-mar 54
        public function raLogin($email) {
55
                if (strpos($email, '|') !== false) return;
56
 
585 daniel-mar 57
                $list = $this->getValue('oidplus_ra_logged_in');
566 daniel-mar 58
                if (is_null($list)) $list = '';
59
 
60
                $ary = ($list == '') ? array() : explode('|', $list);
61
                if (!in_array($email, $ary)) $ary[] = $email;
62
                $list = implode('|', $ary);
63
 
585 daniel-mar 64
                $this->setValue('oidplus_ra_logged_in', $list);
566 daniel-mar 65
        }
66
 
67
        public function raLogout($email) {
585 daniel-mar 68
                $list = $this->getValue('oidplus_ra_logged_in');
566 daniel-mar 69
                if (is_null($list)) $list = '';
70
 
71
                $ary = ($list == '') ? array() : explode('|', $list);
72
                $key = array_search($email, $ary);
73
                if ($key !== false) unset($ary[$key]);
74
                $list = implode('|', $ary);
75
 
585 daniel-mar 76
                $this->setValue('oidplus_ra_logged_in', $list);
566 daniel-mar 77
        }
78
 
79
        public function raNumLoggedIn() {
585 daniel-mar 80
                return count($this->loggedInRaList());
566 daniel-mar 81
        }
82
 
83
        public function loggedInRaList() {
585 daniel-mar 84
                $list = $this->getValue('oidplus_ra_logged_in');
566 daniel-mar 85
                if (is_null($list)) $list = '';
86
 
87
                $res = array();
88
                foreach (array_unique(explode('|',$list)) as $ra_email) {
89
                        if ($ra_email == '') continue;
90
                        $res[] = new OIDplusRA($ra_email);
91
                }
92
                return $res;
93
        }
94
 
95
        public function isRaLoggedIn($email) {
585 daniel-mar 96
                foreach ($this->loggedInRaList() as $ra) {
566 daniel-mar 97
                        if ($email == $ra->raEmail()) return true;
98
                }
99
                return false;
100
        }
101
 
585 daniel-mar 102
        // Admin authentication functions (low-level)
566 daniel-mar 103
 
104
        public function adminLogin() {
570 daniel-mar 105
                $this->setValue('oidplus_admin_logged_in', 1);
566 daniel-mar 106
        }
107
 
108
        public function adminLogout() {
570 daniel-mar 109
                $this->setValue('oidplus_admin_logged_in', 0);
566 daniel-mar 110
        }
111
 
112
        public function isAdminLoggedIn() {
570 daniel-mar 113
                return $this->getValue('oidplus_admin_logged_in') == 1;
566 daniel-mar 114
        }
115
 
116
}