Subversion Repositories oidplus

Rev

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

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. abstract class OIDplusAuthContentStore extends OIDplusBaseClass implements OIDplusGetterSetterInterface {
  27.  
  28.         // Getter / Setter
  29.  
  30.         public abstract function getValue($name, $default = NULL);
  31.  
  32.         public abstract function setValue($name, $value);
  33.  
  34.         public abstract function exists($name);
  35.  
  36.         public abstract function delete($name);
  37.  
  38.         public abstract static function getActiveProvider();
  39.  
  40.         public abstract function destroySession();
  41.  
  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.  
  54.         public function raLogin($email) {
  55.                 if (strpos($email, '|') !== false) return;
  56.  
  57.                 $list = $this->getValue('oidplus_ra_logged_in');
  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.  
  64.                 $this->setValue('oidplus_ra_logged_in', $list);
  65.         }
  66.  
  67.         public function raLogout($email) {
  68.                 $list = $this->getValue('oidplus_ra_logged_in');
  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.  
  76.                 $this->setValue('oidplus_ra_logged_in', $list);
  77.         }
  78.  
  79.         public function raNumLoggedIn() {
  80.                 return count($this->loggedInRaList());
  81.         }
  82.  
  83.         public function loggedInRaList() {
  84.                 $list = $this->getValue('oidplus_ra_logged_in');
  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) {
  96.                 foreach ($this->loggedInRaList() as $ra) {
  97.                         if ($email == $ra->raEmail()) return true;
  98.                 }
  99.                 return false;
  100.         }
  101.  
  102.         // Admin authentication functions (low-level)
  103.  
  104.         public function adminLogin() {
  105.                 $this->setValue('oidplus_admin_logged_in', 1);
  106.         }
  107.  
  108.         public function adminLogout() {
  109.                 $this->setValue('oidplus_admin_logged_in', 0);
  110.         }
  111.  
  112.         public function isAdminLoggedIn() {
  113.                 return $this->getValue('oidplus_admin_logged_in') == 1;
  114.         }
  115.  
  116. }
  117.