From e1b249d0d87715a8905433c2e1842fa78cfeaffd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 23 Mar 2011 11:43:49 +1300 Subject: [PATCH] BUGFIX Allowing Security controller methods to work without Page or Page_Controller classes (now moved to 'cms' module) --- security/Security.php | 74 +++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/security/Security.php b/security/Security.php index 722603dba..71982188d 100644 --- a/security/Security.php +++ b/security/Security.php @@ -83,6 +83,8 @@ class Security extends Controller { */ protected static $wordlist = './wordlist.txt'; + static $template = 'BlankPage'; + /** * Template thats used to render the pages. * @@ -339,15 +341,20 @@ class Security extends Controller { Requirements::css($customCSS); } - $tmpPage = new Page(); - $tmpPage->Title = _t('Security.LOGIN', 'Log in'); - $tmpPage->URLSegment = "Security"; - // Disable ID-based caching of the log-in page by making it a random number - $tmpPage->ID = -1 * rand(1,10000000); + if(class_exists('SiteTree')) { + $tmpPage = new Page(); + $tmpPage->Title = _t('Security.LOGIN', 'Log in'); + $tmpPage->URLSegment = "Security"; + // Disable ID-based caching of the log-in page by making it a random number + $tmpPage->ID = -1 * rand(1,10000000); + + $controller = new Page_Controller($tmpPage); + $controller->init(); + //Controller::$currentController = $controller; + } else { + $controller = $this; + } - $controller = new Page_Controller($tmpPage); - $controller->init(); - //Controller::$currentController = $controller; $content = ''; $forms = $this->GetLoginForms(); @@ -436,12 +443,16 @@ class Security extends Controller { Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js'); - $tmpPage = new Page(); - $tmpPage->Title = _t('Security.LOSTPASSWORDHEADER', 'Lost Password'); - $tmpPage->URLSegment = 'Security'; - $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children - $controller = new Page_Controller($tmpPage); - $controller->init(); + if(class_exists('SiteTree')) { + $tmpPage = new Page(); + $tmpPage->Title = _t('Security.LOSTPASSWORDHEADER', 'Lost Password'); + $tmpPage->URLSegment = 'Security'; + $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children + $controller = new Page_Controller($tmpPage); + $controller->init(); + } else { + $controller = $this; + } $customisedController = $controller->customise(array( 'Content' => @@ -495,12 +506,16 @@ class Security extends Controller { Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/effects.js'); - $tmpPage = new Page(); - $tmpPage->Title = _t('Security.LOSTPASSWORDHEADER'); - $tmpPage->URLSegment = 'Security'; - $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children - $controller = new Page_Controller($tmpPage); - $controller->init(); + if(class_exists('SiteTree')) { + $tmpPage = new Page(); + $tmpPage->Title = _t('Security.LOSTPASSWORDHEADER'); + $tmpPage->URLSegment = 'Security'; + $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children + $controller = new Page_Controller($tmpPage); + $controller->init(); + } else { + $controller = $this; + } $email = Convert::raw2xml($request->param('ID') . '.' . $request->getExtension()); @@ -541,12 +556,16 @@ class Security extends Controller { * @return string Returns the "change password" page as HTML code. */ public function changepassword() { - $tmpPage = new Page(); - $tmpPage->Title = _t('Security.CHANGEPASSWORDHEADER', 'Change your password'); - $tmpPage->URLSegment = 'Security'; - $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children - $controller = new Page_Controller($tmpPage); - $controller->init(); + if(class_exists('SiteTree')) { + $tmpPage = new Page(); + $tmpPage->Title = _t('Security.CHANGEPASSWORDHEADER', 'Change your password'); + $tmpPage->URLSegment = 'Security'; + $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children + $controller = new Page_Controller($tmpPage); + $controller->init(); + } else { + $controller = $this; + } // First load with hash: Redirect to same URL without hash to avoid referer leakage if(isset($_REQUEST['h']) && Member::member_from_autologinhash($_REQUEST['h'])) { @@ -934,5 +953,4 @@ class Security extends Controller { return self::$default_login_dest; } -} -?> +} \ No newline at end of file