當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Authenticator::bind方法代碼示例

本文整理匯總了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'])) {
//.........這裏部分代碼省略.........
開發者ID:rair,項目名稱:yacs,代碼行數:101,代碼來源:users.php


注:本文中的Authenticator::bind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。