Subversion Repositories oidplus

Rev

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