本文整理汇总了PHP中BasicAuth类的典型用法代码示例。如果您正苦于以下问题:PHP BasicAuth类的具体用法?PHP BasicAuth怎么用?PHP BasicAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BasicAuth类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: index
public function index() {
ContentNegotiator::disable();
BasicAuth::disable();
$request_count = count($_REQUEST);
$get_count = count($_GET);
$post_count = count($_POST);
$request = '';
foreach ($_REQUEST as $key=>$value) {
$request .= "\t\t<request_item name=\"$key\">$value</request_item>\n";
}
$get = '';
foreach ($_GET as $key => $value) {
$get .= "\t\t<get_item name=\"$key\">$value</get_item>\n";
}
$post = '';
foreach ($_POST as $key => $value) {
$post .= "\t\t<post_item name=\"$key\">$value</post_item>\n";
}
$out = <<<XML
<?xml version="1.0"?>
<test>
<request count="$request_count">
$request </request>
<get count="$get_count">
$get </get>
<post count="$post_count">
$post </post>
</test>
XML;
header('Content-type: text/xml');
echo $out;
}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:32,代码来源:RestfulServiceTest.php
示例2: 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();
}
// This is used to test that subordinate controllers are actually calling parent::init() - a common bug
$this->baseInitCalled = true;
}
开发者ID:nickbooties,项目名称:silverstripe-framework,代码行数:13,代码来源:Controller.php
示例3: setUpOnce
public function setUpOnce()
{
parent::setUpOnce();
Restrictable::set_enabled(false);
BasicAuth::protect_entire_site(false);
// needs to be done this way to work around SS bug
// include_once dirname(dirname(__FILE__)).'/extensions/Restrictable.php';
// Object::add_extension('PrivateObject', 'Restrictable');
}
开发者ID:helpfulrobot,项目名称:silverstripe-restrictedobjects,代码行数:9,代码来源:TestRestrictedObject.php
示例4: pageLoad
public function pageLoad()
{
$login = BasicAuth::validate();
if (empty($login) || !isset($login)) {
$this->redirect('login');
return;
}
$this->content['custom_html'] = Lang::get('WELCOME', $login);
}
开发者ID:nguyennhuanh,项目名称:tjm-mvc,代码行数:9,代码来源:RestrictPageModel.php
示例5: initLogin
public function initLogin()
{
App::import('vendor', array('db', 'api.basic_auth'));
$id = BasicAuth::getCurrentUser();
if (false === $id) {
$this->controller->error(ECode::$LOGIN_ERROR);
}
$this->isLogin = $id !== 'guest';
if ('guest' !== $id) {
$ret = Forum::checkBanIP($id, $this->from);
switch ($ret) {
case 1:
$this->controller->error(ECode::$LOGIN_IPBAN);
break;
case 2:
$this->controller->error(ECode::$LOGIN_EPOS);
break;
case 3:
$this->controller->error(ECode::$LOGIN_ERROR);
break;
}
}
$db = DB::getInstance();
if ($u = $db->one('select id, utmpnum, utmpkey from pl_api_session where id=?', array($id))) {
if (Forum::initUser($u['id'], intval($u['utmpnum']), intval($u['utmpkey']))) {
$val = array('expire' => time() + $this->_expire);
$db->update('pl_api_session', $val, 'where id=?', array($u['id']));
return;
}
}
$ret = Forum::setUser(true);
switch ($ret) {
case -1:
$this->controller->error(ECode::$LOGIN_MULLOGIN);
case 1:
$this->controller->error(ECode::$LOGIN_MAX);
case 3:
$this->controller->error(ECode::$LOGIN_IDBAN);
case 4:
$this->controller->error(ECode::$LOGIN_IPBAN);
case 5:
$this->controller->error(ECode::$LOGIN_FREQUENT);
case 7:
$this->controller->error(ECode::$LOGIN_NOPOS);
}
User::update();
$user = User::getInstance();
if ($u) {
$val = array('utmpnum' => $user->index, 'utmpkey' => $user->utmpkey, 'expire' => time() + $this->_expire);
$db->update('pl_api_session', $val, 'where id=?', array($user->userid));
} else {
$val = array('k' => array('id', 'utmpnum', 'utmpkey', 'expire'), 'v' => array(array($user->userid, $user->index, $user->utmpkey, time() + $this->_expire)));
$db->insert('pl_api_session', $val);
}
}
开发者ID:tilitala,项目名称:nForum,代码行数:55,代码来源:api_session.php
示例6: getBasicAuthMember
/**
* @return \Member
*/
protected static function getBasicAuthMember()
{
$realm = \Config::inst()->get('HttpAuth', 'Realm');
$permissionCode = \Config::inst()->get('HttpAuth', 'PermissionCode');
$isRunningTests = class_exists('SapphireTest', false) && \SapphireTest::is_running_test();
$tryUsingSessionLogin = $isRunningTests || \Config::inst()->get('HttpAuth', 'TryUsingSessionLogin');
try {
$member = \BasicAuth::requireLogin($realm, $permissionCode, $tryUsingSessionLogin);
return $member;
} catch (\Exception $ex) {
return null;
}
}
开发者ID:notthatbad,项目名称:silverstripe-rest-api,代码行数:16,代码来源:HttpAuth.php
示例7: 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
示例8: 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
示例9: setUp
function setUp()
{
parent::setUp();
$this->mainSession = new TestSession();
// Disable theme, if necessary
if ($this->stat('disable_themes')) {
SSViewer::set_theme(null);
}
// Switch to draft site, if necessary
if ($this->stat('use_draft_site')) {
$this->useDraftSite();
}
// Unprotect the site, tests are running with the assumption it's off. They will enable it on a case-by-case basis.
BasicAuth::protect_entire_site(false);
SecurityToken::disable();
}
开发者ID:hamishcampbell,项目名称:silverstripe-sapphire,代码行数:16,代码来源:FunctionalTest.php
示例10: checkPerm
/**
* If not logged in attempt HTTP auth and check permission, otherwise check logged in members permission
* @throws PermissionFailureException
* @return ReplicantAction this
*/
public function checkPerm()
{
if (!($member = Member::currentUserID())) {
if ($member = BasicAuth::requireLogin("Replicant", static::$required_permission, true)) {
$member->logIn();
$res = true;
}
} else {
$res = Permission::check(static::$required_permission);
}
if (!$res) {
$this->failed("Permission Failure: " . static::$required_permission)->output();
throw new PermissionFailureException("Not allowed to " . static::$required_permission);
}
return $this;
}
开发者ID:helpfulrobot,项目名称:govtnz-replicant,代码行数:21,代码来源:ReplicantAction.php
示例11: 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
示例12: 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
示例13: setUp
public function setUp()
{
// Skip calling FunctionalTest directly.
if (get_class($this) == "FunctionalTest") {
$this->skipTest = true;
}
parent::setUp();
$this->mainSession = new TestSession();
// Disable theme, if necessary
if (static::get_disable_themes()) {
Config::inst()->update('SSViewer', 'theme', null);
}
// Switch to draft site, if necessary
if (static::get_use_draft_site()) {
$this->useDraftSite();
}
// Unprotect the site, tests are running with the assumption it's off. They will enable it on a case-by-case
// basis.
BasicAuth::protect_entire_site(false);
SecurityToken::disable();
}
开发者ID:jareddreyer,项目名称:catalogue,代码行数:21,代码来源:FunctionalTest.php
示例14: index
function index($request)
{
// For 2.3 and 2.4 compatibility
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
BasicAuth::enable();
BasicAuth::requireLogin("CMS RSS feed access. Use your CMS login", "CMS_ACCESS_CMSMain");
$member = $this->getBasicAuthMember();
// Due to a bug in 2.3.0 we can't get the information that we need from $request
$params = Director::urlParams();
// Default value
if (!isset($params['Data']) || !$params['Data']) {
$params['Data'] = 'all';
}
switch ($params['Data']) {
case 'all':
$changes = $this->changes();
break;
case 'page':
if ((int) $params['PageID']) {
$changes = $this->changes("{$bt}SiteTree{$bt}.{$bt}ID{$bt} = " . (int) $params['PageID']);
} else {
return new HTTPResponse("<h1>Bad Page ID</h1><p>Bad page ID when getting RSS feed of changes to a page.</p>", 400);
}
break;
default:
user_error("CMSChangeTracker Data param value '{$params['Data']}' not implemented; this is probably due to a bad URL rule.", E_USER_ERROR);
}
$processedChanges = new DataObjectSet();
foreach ($changes as $change) {
if ($change->canEdit($member)) {
$author = DataObject::get_by_id("Member", $change->AuthorID);
$verbed = $change->Version == 1 ? "created" : "edited";
if ($author) {
$changeTitle = "'{$change->Title}' {$verbed} by {$author->FirstName} {$author->Surname}";
$changeAuthor = "{$author->FirstName} {$author->Surname}";
$firstParagraph = "{$author->FirstName} {$author->Surname} (<a href=\"mailto:{$author->Email}\">{$author->Email}</a>) has {$verbed} the '{$change->Title}' page.";
} else {
$changeTitle = "'{$change->Title}' {$verbed}";
$changeAuthor = "";
$firstParagraph = "The '{$change->Title}' page has been {$verbed}.";
}
$actionLinks = "";
$cmsLink = Director::absoluteURL("admin/show/{$change->ID}");
$actionLinks .= "<li><a href=\"{$cmsLink}\">Edit in CMS</a></li>\n";
$page = DataObject::get_by_id('SiteTree', $change->ID);
if ($page) {
$link = $page->AbsoluteLink();
$actionLinks .= "<li><a href=\"{$link}\">See the page on site</a></li>\n";
}
if ($change->Version > 1) {
$prevVersion = $change->Version - 1;
$diffLink = Director::absoluteURL("admin/compareversions/{$change->ID}/?From={$prevVersion}&To={$change->Version}");
$actionLinks .= "<li><a href=\"{$diffLink}\">See the changes in CMS</a></li>\n";
}
$changeDescription = <<<HTML
<p>{$firstParagraph}</p>
<h3>Actions and links</h3>
<ul>
\t{$actionLinks}
</ul>
HTML;
$processedChange = new CMSChangeTracker_Change(array("ChangeTitle" => $changeTitle, "Author" => $changeAuthor, "Content" => $changeDescription, "Link" => $change->Link() . "version/{$change->Version}"));
$processedChanges->push($processedChange);
}
}
$feed = new RSSFeed($processedChanges, Director::absoluteURL("admin/"), "SilverStripe Content Changes", "", "ChangeTitle");
return $feed->outputToBrowser();
}
开发者ID:helpfulrobot,项目名称:silverstripe-cmsworkflow,代码行数:70,代码来源:CMSChangeTracker.php
示例15: logout
protected function logout($args)
{
BasicAuth::logout();
}
开发者ID:nguyennhuanh,项目名称:tjm-mvc,代码行数:4,代码来源:LoginPageModel.php
示例16: session_start
<?php
session_start();
/* Aquire neccessary libs */
require_once "external/class.auth.module.core.php";
require_once "external/class.database.mysql.external.php";
/* Declare classes */
$Auth = new BasicAuth();
$DB = new Database($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']);
$sessionCurrentStatus = false;
/* Handle login request */
if (isset($_POST['login']) and isset($_POST['password'])) {
$providedName = $_POST['login'];
$providedPassword = $_POST['password'];
/* Find if users exists */
$userName = $DB->escapeData($providedName);
$userParameters = $DB->getData("users", "WHERE login='" . $userName . "'");
if (count($userParameters) == 0) {
/* DO SOMETHING IN THAT CASE */
} else {
$Authenticated = $Auth->AuthOnSSHA($providedPassword, $userParameters[0]['password']);
if ($Authenticated) {
$Auth->sessionEstablish($userParameters[0]);
unset($_POST);
header("Location: " . $config['system_root']);
die;
} else {
/* DO SOMETHING IN THAT CASE */
}
}
}
开发者ID:Elentra,项目名称:ansible-ui-disp,代码行数:31,代码来源:auth.container.php
示例17: 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
示例18: invalid
public function invalid()
{
BasicAuth::protect_entire_site(false);
$out = <<<XML
<?xml version="1.0"?>
<test>
\t<fail><invalid>
</test>
XML;
header('Content-type: text/xml');
echo $out;
}
开发者ID:NARKOZ,项目名称:silverstripe-doc-restructuring,代码行数:12,代码来源:RestfulServiceTest.php
示例19: array
<?php
global $project;
$project = 'mysite';
global $database;
$database = 'SS_ssnewdocstest';
require_once 'conf/ConfigureFromEnv.php';
MySQLDatabase::set_connection_charset('utf8');
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.org/themes/
SSViewer::set_theme('docs');
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
// render the user documentation first
Director::addRules(20, array('Security//$Action/$ID/$OtherID' => 'Security'));
DocumentationViewer::set_link_base('');
DocumentationViewer::$check_permission = false;
Director::addRules(10, array('$Action' => 'DocumentationViewer', '' => '->current/en/cms'));
DocumentationService::set_automatic_registration(false);
DocumentationService::register("cms", realpath("../../master/cms/docs/"), '2.4');
// We want this to be reviewed by the whole community
BasicAuth::protect_entire_site(false);
开发者ID:NARKOZ,项目名称:silverstripe-doc-restructuring,代码行数:22,代码来源:_config.php
示例20: dirname
if (!isset($database) || !$database) {
// if SS_DATABASE_CHOOSE_NAME
if (defined('SS_DATABASE_CHOOSE_NAME') && SS_DATABASE_CHOOSE_NAME) {
$loopCount = (int) SS_DATABASE_CHOOSE_NAME;
$databaseDir = dirname($_SERVER['SCRIPT_FILENAME']);
for ($i = 0; $i < $loopCount; $i++) {
$databaseDir = dirname($databaseDir);
}
$database = "SS_" . basename($databaseDir);
$database = str_replace('.', '', $database);
}
}
if (defined('SS_DATABASE_USERNAME') && defined('SS_DATABASE_PASSWORD')) {
global $databaseConfig;
$databaseConfig = array("type" => "MySQLDatabase", "server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : 'localhost', "username" => SS_DATABASE_USERNAME, "password" => SS_DATABASE_PASSWORD, "database" => (defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : '') . $database . (defined('SS_DATABASE_SUFFIX') ? SS_DATABASE_SUFFIX : ''));
}
if (defined('SS_SEND_ALL_EMAILS_TO')) {
Email::send_all_emails_to(SS_SEND_ALL_EMAILS_TO);
}
if (defined('SS_DEFAULT_ADMIN_USERNAME')) {
if (!defined('SS_DEFAULT_ADMIN_PASSWORD')) {
user_error("SS_DEFAULT_ADMIN_PASSWORD must be defined in your _ss_environment.php, if SS_DEFAULT_ADMIN_USERNAME is defined. See http://doc.silverstripe.com/doku.php?id=environment-management for more infomration", E_USER_ERROR);
}
Security::setDefaultAdmin(SS_DEFAULT_ADMIN_USERNAME, SS_DEFAULT_ADMIN_PASSWORD);
}
if (defined('SS_USE_BASIC_AUTH') && SS_USE_BASIC_AUTH) {
BasicAuth::protect_entire_site();
}
if (defined('SS_ERROR_LOG')) {
Debug::log_errors_to(SS_ERROR_LOG);
}
开发者ID:racontemoi,项目名称:shibuichi,代码行数:31,代码来源:ConfigureFromEnv.php
注:本文中的BasicAuth类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论