Subversion Repositories oidplus

Rev

Rev 567 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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 implements OIDplusConfigInterface {
  23.  
  24.         protected $content = array();
  25.  
  26.         // Getter / Setter
  27.  
  28.         public abstract function getValue($name, $default = NULL);
  29.  
  30.         public abstract function setValue($name, $value);
  31.  
  32.         public abstract function exists($name);
  33.  
  34.         public abstract function delete($name);
  35.  
  36.         protected abstract function destroySession();
  37.  
  38.         // RA authentication functions
  39.  
  40.         public function raLogin($email) {
  41.                 if (strpos($email, '|') !== false) return;
  42.  
  43.                 $list = $this->getValue('oidplus_logged_in');
  44.                 if (is_null($list)) $list = '';
  45.  
  46.                 $ary = ($list == '') ? array() : explode('|', $list);
  47.                 if (!in_array($email, $ary)) $ary[] = $email;
  48.                 $list = implode('|', $ary);
  49.  
  50.                 $this->setValue('oidplus_logged_in', $list);
  51.         }
  52.  
  53.         public function raLogout($email) {
  54.                 $list = $this->getValue('oidplus_logged_in');
  55.                 if (is_null($list)) $list = '';
  56.  
  57.                 $ary = ($list == '') ? array() : explode('|', $list);
  58.                 $key = array_search($email, $ary);
  59.                 if ($key !== false) unset($ary[$key]);
  60.                 $list = implode('|', $ary);
  61.  
  62.                 $this->setValue('oidplus_logged_in', $list);
  63.  
  64.                 if (($list == '') && (!self::isAdminLoggedIn())) {
  65.                         // Nobody logged in anymore. Destroy session cookie to make GDPR people happy
  66.                         $this->destroySession();
  67.                 }
  68.         }
  69.  
  70.         public function raNumLoggedIn() {
  71.                 return count(self::loggedInRaList());
  72.         }
  73.  
  74.         public function raLogoutAll() {
  75.                 $this->setValue('oidplus_logged_in', '');
  76.         }
  77.  
  78.         public function loggedInRaList() {
  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.                 return $this->getValue('oidplus_admin_logged_in') == '1';
  114.         }
  115.  
  116. }
  117.