当前位置: 首页>>代码示例>>PHP>>正文


PHP Security::database_is_ready方法代码示例

本文整理汇总了PHP中Security::database_is_ready方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::database_is_ready方法的具体用法?PHP Security::database_is_ready怎么用?PHP Security::database_is_ready使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Security的用法示例。


在下文中一共展示了Security::database_is_ready方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: requireLogin

 /**
  * Require basic authentication.  Will request a username and password if none is given.
  * 
  * Used by {@link Controller::init()}.
  * 
  * @param string $realm
  * @param string|array $permissionCode
  * @return Member $member 
  */
 static function requireLogin($realm, $permissionCode)
 {
     if (!Security::database_is_ready() || Director::is_cli()) {
         return true;
     }
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
         if ($member) {
             $authenticated = true;
         }
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!isset($authenticated)) {
         header("WWW-Authenticate: Basic realm=\"{$realm}\"");
         header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized');
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             echo _t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised");
         } else {
             echo _t('BasicAuth.ENTERINFO', "Please enter a username and password.");
         }
         die;
     }
     if (!Permission::checkMember($member->ID, $permissionCode)) {
         header("WWW-Authenticate: Basic realm=\"{$realm}\"");
         header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized');
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             echo _t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator.");
         }
         die;
     }
     return $member;
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:41,代码来源:BasicAuth.php

示例2: logVisit

 protected function logVisit()
 {
     if (!Security::database_is_ready()) {
         return;
     }
     DB::query(sprintf('UPDATE "Member" SET "LastVisited" = %s, "NumVisit" = "NumVisit" + 1 WHERE "ID" = %d', DB::get_conn()->now(), $this->owner->ID));
 }
开发者ID:andrelohmann,项目名称:roof-for-refugees.org,代码行数:7,代码来源:VisitsMemberExtension.php

示例3: requireLogin

 /**
  * Require basic authentication.  Will request a username and password if none is given.
  *
  * Used by {@link Controller::init()}.
  *
  * @throws SS_HTTPResponse_Exception
  *
  * @param string $realm
  * @param string|array $permissionCode Optional
  * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
  *  session log-in if those credentials are disabled.
  * @return Member $member
  */
 public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true)
 {
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) {
         return true;
     }
     /*
      * Enable HTTP Basic authentication workaround for PHP running in CGI mode with Apache
      * Depending on server configuration the auth header may be in HTTP_AUTHORIZATION or
      * REDIRECT_HTTP_AUTHORIZATION
      *
      * The follow rewrite rule must be in the sites .htaccess file to enable this workaround
      * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      */
     $authHeader = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : null);
     $matches = array();
     if ($authHeader && preg_match('/Basic\\s+(.*)$/i', $authHeader, $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     $member = null;
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
     }
     if (!$member && $tryUsingSessionLogin) {
         $member = Member::currentUser();
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!$member) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"));
         } else {
             $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     return $member;
 }
开发者ID:XDdesigners,项目名称:silverstripe-framework,代码行数:68,代码来源:BasicAuth.php

示例4: populateDefaults

 function populateDefaults()
 {
     parent::populateDefaults();
     $this->Title = _t("OrderStatusLog.ORDERDISPATCHED", "Order Dispatched");
     $this->DispatchedOn = date('Y-m-d');
     if (Security::database_is_ready()) {
         if (Member::currentUser()) {
             $this->DispatchedBy = Member::currentUser()->getTitle();
         }
     }
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce,代码行数:11,代码来源:OrderStatusLog_DispatchPhysicalOrder.php

示例5: init

 function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // if on CLI or with the database not ready. The latter makes it less errorprone to do an
     // initial schema build without requiring a default-admin login.
     // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
     $canAccess = Director::isDev() || !Security::database_is_ready() || Director::is_cli() && !SapphireTest::is_running_test() || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:12,代码来源:DatabaseAdmin.php

示例6: build

 /**
  * Updates the database schema, creating tables & fields as necessary.
  */
 function build()
 {
     if (Director::isLive() && Security::database_is_ready() && (!Member::currentUser() || !Member::currentUser()->isAdmin())) {
         Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
         return;
     }
     // The default time limit of 30 seconds is normally not enough
     if (ini_get("safe_mode") != "1") {
         set_time_limit(600);
     }
     $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']));
 }
开发者ID:ramziammar,项目名称:websites,代码行数:15,代码来源:DatabaseAdmin.php

示例7: init

 /**
  * Initialisation function that is run before any action on the controller is called.
  *
  * @uses BasicAuth::requireLogin()
  */
 public function init()
 {
     if ($this->basicAuthEnabled) {
         BasicAuth::protect_site_if_necessary();
     }
     // Directly access the session variable just in case the Group or Member tables don't yet exist
     if (Member::config()->log_last_visited) {
         Deprecation::notice('4.0', 'Member::$LastVisited is deprecated. From 4.0 onwards you should implement this as a custom extension');
         if (Session::get('loggedInAs') && Security::database_is_ready() && ($member = Member::currentUser())) {
             DB::prepared_query(sprintf('UPDATE "Member" SET "LastVisited" = %s WHERE "ID" = ?', DB::get_conn()->now()), array($member->ID));
         }
     }
     // This is used to test that subordinate controllers are actually calling parent::init() - a common bug
     $this->baseInitCalled = true;
 }
开发者ID:miamollie,项目名称:echoAerial,代码行数:20,代码来源:Controller.php

示例8: init

	/**
	 * Initialisation function that is run before any action on the controller is called.
	 * 
	 * @uses BasicAuth::requireLogin()
	 */
	function init() {
		if($this->basicAuthEnabled) BasicAuth::protect_site_if_necessary();

		// Directly access the session variable just in case the Group or Member tables don't yet exist
		if(Session::get('loggedInAs') && Security::database_is_ready()) {
			$member = Member::currentUser();
			if($member) {
				if(!headers_sent()) Cookie::set("PastMember", true, 90, null, null, false, true);
				DB::query("UPDATE \"Member\" SET \"LastVisited\" = " . DB::getConn()->now() . " WHERE \"ID\" = $member->ID", null);
			}
		}
		
		// This is used to test that subordinate controllers are actually calling parent::init() - a common bug
		$this->baseInitCalled = true;
	}
开发者ID:redema,项目名称:sapphire,代码行数:20,代码来源:Controller.php

示例9: init

 /**
  * Initialisation function that is run before any action on the controller is called.
  * 
  * @uses BasicAuth::requireLogin()
  */
 function init()
 {
     if ($this->basicAuthEnabled) {
         BasicAuth::protect_site_if_necessary();
     }
     // Directly access the session variable just in case the Group or Member tables don't yet exist
     if (Session::get('loggedInAs') && Security::database_is_ready()) {
         if ($member = Member::currentUser()) {
             if (!headers_sent()) {
                 Cookie::set("PastMember", true);
             }
             DB::query("UPDATE Member SET LastVisited = NOW() WHERE ID = {$member->ID}", null);
         }
     }
     // This is used to test that subordinate controllers are actually calling parent::init() - a common bug
     $this->baseInitCalled = true;
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:22,代码来源:Controller.php

示例10: init

 public function init()
 {
     parent::init();
     // We allow access to this controller regardless of live-status or ADMIN permission only
     // if on CLI or with the database not ready. The latter makes it less errorprone to do an
     // initial schema build without requiring a default-admin login.
     // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     $canAccess = Director::isDev() || !Security::database_is_ready() || Director::is_cli() && !$isRunningTests || Permission::check("ADMIN");
     if (!$canAccess) {
         return Security::permissionFailure($this, "This page is secured and you need administrator rights to access it. " . "Enter your credentials below and we will send you right along.");
     }
     //render the debug view
     $renderer = Object::create('DebugView');
     $renderer->writeHeader();
     $renderer->writeInfo(_t("Shop.DEVTOOLSTITLE", "Shop Development Tools"), Director::absoluteBaseURL());
 }
开发者ID:NobrainerWeb,项目名称:silverstripe-shop,代码行数:17,代码来源:ShopDevelopmentAdmin.php

示例11: requireLogin

 /**
  * Require basic authentication.  Will request a username and password if none is given.
  *
  * Used by {@link Controller::init()}.
  *
  * @throws SS_HTTPResponse_Exception
  *
  * @param string $realm
  * @param string|array $permissionCode Optional
  * @param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
  *  session log-in if those credentials are disabled.
  * @return Member $member
  */
 public static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true)
 {
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     if (!Security::database_is_ready() || Director::is_cli() && !$isRunningTests) {
         return true;
     }
     $matches = array();
     if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     $member = null;
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $member = MemberAuthenticator::authenticate(array('Email' => $_SERVER['PHP_AUTH_USER'], 'Password' => $_SERVER['PHP_AUTH_PW']), null);
     }
     if (!$member && $tryUsingSessionLogin) {
         $member = Member::currentUser();
     }
     // If we've failed the authentication mechanism, then show the login form
     if (!$member) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTREC', "That username / password isn't recognised"));
         } else {
             $response->setBody(_t('BasicAuth.ENTERINFO', "Please enter a username and password."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
         $response = new SS_HTTPResponse(null, 401);
         $response->addHeader('WWW-Authenticate', "Basic realm=\"{$realm}\"");
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $response->setBody(_t('BasicAuth.ERRORNOTADMIN', "That user is not an administrator."));
         }
         // Exception is caught by RequestHandler->handleRequest() and will halt further execution
         $e = new SS_HTTPResponse_Exception(null, 401);
         $e->setResponse($response);
         throw $e;
     }
     return $member;
 }
开发者ID:vinstah,项目名称:body,代码行数:59,代码来源:BasicAuth.php

示例12: init

	/**
	 * Initialisation function that is run before any action on the controller is called.
	 * 
	 * @uses BasicAuth::requireLogin()
	 */
	function init() {
		// Test and development sites should be secured, via basic-auth
		if(Director::isTest() && $this->basicAuthEnabled && Security::database_is_ready()) {
			BasicAuth::requireLogin("SilverStripe test website.  Use your  CMS login", "ADMIN");
		}		

		// Directly access the session variable just in case the Group or Member tables don't yet exist
		if(Session::get('loggedInAs') && Security::database_is_ready()) {
			if($member = Member::currentUser()) {
				Cookie::set("PastMember", true);
				DB::query("UPDATE Member SET LastVisited = NOW() WHERE ID = $member->ID", null);
			}
		}
		
		// This is used to test that subordinate controllers are actually calling parent::init() - a common bug
		$this->baseInitCalled = true;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:22,代码来源:Controller.php

示例13: build

	/**
	 * Updates the database schema, creating tables & fields as necessary.
	 */
	function build() {
		if(Director::isLive() && Security::database_is_ready() && !Director::is_cli() && !Permission::check("ADMIN")) {
			Security::permissionFailure($this,
				"This page is secured and you need administrator rights to access it. " .
				"Enter your credentials below and we will send you right along.");
			return;
		}

		// The default time limit of 30 seconds is normally not enough
		if(ini_get("safe_mode") != "1") {
			set_time_limit(600);
		}

		// Get all our classes
		ManifestBuilder::create_manifest_file();
		require(MANIFEST_FILE);
		
		$this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate']));
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:22,代码来源:DatabaseAdmin.php

示例14: init

	function init() {
		parent::init();
		
		// We allow access to this controller regardless of live-status or ADMIN permission only
		// if on CLI or with the database not ready. The latter makes it less errorprone to do an
		// initial schema build without requiring a default-admin login.
		// Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
		$isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test());
		$canAccess = (
			Director::isDev() 
			|| !Security::database_is_ready() 
			// We need to ensure that DevelopmentAdminTest can simulate permission failures when running
			// "dev/tests" from CLI. 
			|| (Director::is_cli() && !$isRunningTests)
			|| Permission::check("ADMIN")
		);
		if(!$canAccess) {
			return Security::permissionFailure($this,
				"This page is secured and you need administrator rights to access it. " .
				"Enter your credentials below and we will send you right along.");
		}
	}
开发者ID:redema,项目名称:sapphire,代码行数:22,代码来源:DatabaseAdmin.php

示例15: isTest

 /**
  * This function will return true if the site is in a test environment.
  * For information about environment types, see {@link Director::set_environment_type()}.
  */
 static function isTest()
 {
     // Use ?isTest=1 to get test access on the live server, or explicitly set your environment
     if (isset($_GET['isTest'])) {
         if (Security::database_is_ready()) {
             BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN");
             $_SESSION['isTest'] = $_GET['isTest'];
         } else {
             return true;
         }
     }
     if (self::isDev()) {
         return false;
     }
     if (self::$environment_type) {
         return self::$environment_type == 'test';
     }
     // Check if we are running on one of the test servers
     if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], Director::$test_servers)) {
         return true;
     }
     return false;
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:27,代码来源:Director.php


注:本文中的Security::database_is_ready方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。