Subversion Repositories oidplus

Rev

Rev 847 | 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. class OIDplusAuthContentStoreSession extends OIDplusAuthContentStore {
  23.  
  24.         protected static function getSessionHandler() {
  25.                 static $sesHandler = null;
  26.                 if (is_null($sesHandler)) {
  27.                         $sesHandler = new OIDplusSessionHandler();
  28.                 }
  29.                 return $sesHandler;
  30.         }
  31.  
  32.         // Override abstract functions
  33.         # TODO: shouldn't we just include OIDplusSessionHandler in this class?
  34.  
  35.         public function getValue($name, $default = NULL) {
  36.                 try {
  37.                         return self::getSessionHandler()->getValue($name, $default);
  38.                 } catch (\Exception $e) {
  39.                         self::getSessionHandler()->destroySession();
  40.                         // TODO: For some reason If destroySession() is called, we won't get this Exception?!
  41.                         throw new OIDplusException(_L('Internal error with session. Please reload the page and log-in again. %1', $e->getMessage()));
  42.                 }
  43.         }
  44.  
  45.         public function setValue($name, $value) {
  46.                 return self::getSessionHandler()->setValue($name, $value);
  47.         }
  48.  
  49.         public function exists($name) {
  50.                 return self::getSessionHandler()->exists($name);
  51.         }
  52.  
  53.         public function delete($name) {
  54.                 return self::getSessionHandler()->delete($name);
  55.         }
  56.  
  57.         public function destroySession() {
  58.                 return self::getSessionHandler()->destroySession();
  59.         }
  60.  
  61.         public static function getActiveProvider() {
  62.                 static $contentProvider = null;
  63.  
  64.                 if (!$contentProvider) {
  65.                         if (self::getSessionHandler()->isActive()) {
  66.                                 $contentProvider = new OIDplusAuthContentStoreSession();
  67.                         }
  68.                 }
  69.  
  70.                 return $contentProvider;
  71.         }
  72.  
  73.         public function raLoginEx($email, &$loginfo) {
  74.                 $this->raLogin($email);
  75.                 if (is_null(self::getActiveProvider())) {
  76.                         $loginfo = 'into new PHP session';
  77.                 } else {
  78.                         $loginfo = 'into existing PHP session';
  79.                 }
  80.         }
  81.  
  82.         public function adminLoginEx(&$loginfo) {
  83.                 $this->adminLogin();
  84.                 if (is_null(self::getActiveProvider())) {
  85.                         $loginfo = 'into new PHP session';
  86.                 } else {
  87.                         $loginfo = 'into existing PHP session';
  88.                 }
  89.         }
  90.  
  91.         public function raLogoutEx($email, &$loginfo) {
  92.                 $this->raLogout($email);
  93.                 $loginfo = 'from PHP session';
  94.         }
  95.  
  96.         public function adminLogoutEx(&$loginfo) {
  97.                 $this->adminLogout();
  98.                 $loginfo = 'from PHP session';
  99.         }
  100.  
  101.         public function activate() {
  102.                 # Sessions automatically activate during setValue()
  103.                 return;
  104.         }
  105.  
  106. }
  107.