Merge pull request #28537 from greenpeace-cee/standalone-session-management
authorRich Lott <artfulrobot@users.noreply.github.com>
Tue, 19 Dec 2023 11:11:04 +0000 (11:11 +0000)
committerGitHub <noreply@github.com>
Tue, 19 Dec 2023 11:11:04 +0000 (11:11 +0000)
Standalone session management

1  2 
CRM/Logging/Schema.php
CRM/Utils/System/Standalone.php
ext/standaloneusers/sql/auto_install.sql
ext/standaloneusers/sql/auto_uninstall.sql

Simple merge
index 265d2ef4385ebd5f75e618276f29faa2b85e7835,2228b444514c9e0887f24a0235ee61a6464a49fb..8036d7cd13fbaa6d73d06c8e28972e81615d854d
@@@ -584,17 -573,30 +573,37 @@@ class CRM_Utils_System_Standalone exten
        CRM_Core_Error::statusBounce(ts("Access denied"), CRM_Utils_System::url('civicrm'));
      }
      else {
 -      CRM_Utils_System::redirect('/civicrm/login?anonAccessDenied');
 -    }
 +      http_response_code(403);
 +
 +      // render a login page
 +      if (class_exists('CRM_Standaloneusers_Page_Login')) {
 +        $loginPage = new CRM_Standaloneusers_Page_Login();
 +        $loginPage->assign('anonAccessDenied', TRUE);
 +        return $loginPage->run();
 +      }
  
 -    // TODO: Prettier error page
 +      throw new CRM_Core_Exception('Access denied. Standaloneusers extension not found');
 +    }
    }
  
+   /**
+    * Start a new session.
+    */
+   public function sessionStart() {
+     $session_handler = new SessionHandler();
+     session_set_save_handler($session_handler);
+     $session_max_lifetime = Civi::settings()->get('standaloneusers_session_max_lifetime') ?? 1440;
+     session_start([
+       'cookie_httponly'  => 1,
+       'cookie_secure'    => !empty($_SERVER['HTTPS']),
+       'gc_maxlifetime'   => $session_max_lifetime,
+       'name'             => 'SESSCIVISO',
+       'use_cookies'      => 1,
+       'use_only_cookies' => 1,
+       'use_strict_mode'  => 1,
+     ]);
+   }
  }
index c365aad57adb4d01f9abd55c4025586d9afe76c7,ecaaf3c9d6c88796bb6334eefe8de4609507fef1..ae77fcf2f19df8f3d217fad3874053fc928e2804
@@@ -17,8 -17,8 +17,9 @@@
  
  SET FOREIGN_KEY_CHECKS=0;
  
 +DROP TABLE IF EXISTS `civicrm_user_role`;
  DROP TABLE IF EXISTS `civicrm_uf_match`;
+ DROP TABLE IF EXISTS `civicrm_session`;
  DROP TABLE IF EXISTS `civicrm_role`;
  
  SET FOREIGN_KEY_CHECKS=1;
index 8e2ac55abc72dd42b109c0a51bcf54ebb74a751d,5e606032ef5d5d806129f37ffce2ed0a6802d7f3..9a3a7b51883a3401d6b2abcd8bafb362364ffe20
@@@ -17,8 -17,8 +17,9 @@@
  
  SET FOREIGN_KEY_CHECKS=0;
  
 +DROP TABLE IF EXISTS `civicrm_user_role`;
  DROP TABLE IF EXISTS `civicrm_uf_match`;
+ DROP TABLE IF EXISTS `civicrm_session`;
  DROP TABLE IF EXISTS `civicrm_role`;
  
  SET FOREIGN_KEY_CHECKS=1;