本文整理汇总了PHP中Authenticator::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Authenticator::bind方法的具体用法?PHP Authenticator::bind怎么用?PHP Authenticator::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Authenticator
的用法示例。
在下文中一共展示了Authenticator::bind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* login
*
* The script checks provided name and password against the local database.
*
* If no record matches, and if the provided name explicitly mentions some origin server
* (e.g., 'john@foo.bar'), then this server is asked to authenticate the user.
* This is done by transmitting the user name and the password to the origin server,
* through a XML-RPC call ([code]drupal.login[/code] at [script]services/xml_rpc.php[/script]).
* On success the origin server will provide the original id for the user profile.
* Else a null id will be returned.
*
* On successful remote authentication the surfer will be considered as logged, either
* as an associate, a member (default case), or as a subscriber (for closed communities).
*
* On successful remote authentication a 'shadow' user profile will be created locally,
* using another id, and a copy of the authentication url saved in the password field.
* Also the user description explicitly references the original user profile.
* This local record may be referenced in pages published locally.
*
* This means that on subsequent visits the 'shadow' profile will be retrieved, and the origin
* server will be sollicitated again for credentials validation.
* As a consequence the validity of login data is always checked by the server that actually
* stores the original user profile.
* If the user profile is modified or is deleted this change will be taken into account on next login.
*
* @link http://drupal.org/node/312 Using distributed authentication (drupal.org)
*
* This script also allows for a last resort password.
* When a webmaster has lost his password, and if there is no other associate to help,
* he can modify manually the file [code]parameters/control.include.php[/code] to add
* a parameter [code]$context['last_resort_password'][/code], followed by a long passphrase
* of at least seven characters. For example:
* [php]
* $context['last_resort_password'] = 'a quite long passphrase, to be used 1 time';
* [/php]
*
* Then he can authenticate normally, using this password, and any name.
*
* On successful login the returned array contains following named atributes:
* - id - record in the table of users (can be a shadow record)
* - nick_name - name to be displayed in user menu, and server messages
* - email - user e-mail address, if any
* - capability - either 'A'ssociate, 'M'ember, 'S'ubscriber or '?'
*
* @param string the nickname or the email address of the user
* @param string the submitted password
* @return the record of the authenticated surfer, or NULL
*
* @see users/login.php
* @see services/blog.php
*/
public static function login($name, $password)
{
global $context;
// using the last resort password
if (isset($context['last_resort_password']) && strlen(trim($context['last_resort_password'])) >= 1 && $password == $context['last_resort_password']) {
// this is an event to remember
Logger::remember('users/users.php: ' . i18n::c('lrp has logged in'), i18n::c('Login using the last resort password'));
// a fake associate
$user = array();
$user['id'] = 1;
$user['nick_name'] = 'lrp';
$user['email'] = '';
$user['capability'] = 'A';
return $user;
}
// user has not been authenticated yet
$authenticated = FALSE;
$item = NULL;
// search a user profile locally
$query = "SELECT * FROM " . SQL::table_name('users') . " AS users" . " WHERE users.email LIKE '" . SQL::escape($name) . "' OR users.nick_name LIKE '" . SQL::escape($name) . "' OR users.full_name LIKE '" . SQL::escape($name) . "'";
if (isset($context['users_connection']) && ($item = SQL::query_first($query, FALSE, $context['users_connection']))) {
// the user has been explicitly locked
if ($item['capability'] == '?') {
return NULL;
} elseif ($item['authenticate_failures'] >= 3 && $item['authenticate_date'] > gmstrftime('%Y-%m-%d %H:%M:%S', time() - 3600)) {
Logger::error(i18n::s('Wait for one hour to recover from too many failed authentications.'));
return NULL;
// successful local check
} elseif (md5($password) == $item['password']) {
$authenticated = TRUE;
}
}
// we have to authenticate externally, if this has been explicitly allowed
if (!$authenticated && isset($context['users_authenticator']) && $context['users_authenticator']) {
// load and configure an authenticator instance
include_once $context['path_to_root'] . 'users/authenticator.php';
if (!($authenticator = Authenticator::bind($context['users_authenticator']))) {
return NULL;
}
// submit full name to authenticator
if (isset($item['full_name']) && trim($item['full_name']) && $authenticator->login($item['full_name'], $password)) {
$authenticated = TRUE;
} elseif ($authenticator->login($name, $password)) {
$authenticated = TRUE;
}
}
// we have to create a shadow record
if ($authenticated && !isset($item['id'])) {
//.........这里部分代码省略.........