本文整理汇总了PHP中BasicAuth类的典型用法代码示例。如果您正苦于以下问题:PHP BasicAuth类的具体用法?PHP BasicAuth怎么用?PHP BasicAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BasicAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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');
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例15: logout
protected function logout($args)
{
BasicAuth::logout();
}