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


PHP JAuthentication::authenticate方法代碼示例

本文整理匯總了PHP中JAuthentication::authenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP JAuthentication::authenticate方法的具體用法?PHP JAuthentication::authenticate怎麽用?PHP JAuthentication::authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JAuthentication的用法示例。


在下文中一共展示了JAuthentication::authenticate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testAuthenticate

	/**
	 * Testing authenticate
	 *
	 * @return void
	 * @todo Implement testAuthenticate().
	 */
	public function testAuthenticate()
	{
		include_once JPATH_BASE . '/libraries/joomla/plugin/helper.php';
		include_once JPATH_BASE . '/libraries/joomla/user/user.php';
		include_once JPATH_BASE . '/libraries/joomla/session/session.php';

		$user = new JUser;
		/*
		 * The lines below are commented out because they cause an error, but I don't understand why
		 * they do, so I'm leaving them here in case it's a bug that is later fixed and they're needed.
		 */
		$mockSession = $this->getMock('JSession', array( '_start', 'get'));
		//$mockSession->expects($this->any())->method('get')->with($this->equalTo('user'))->will(
		//	$this->returnValue($user)
		//);
		JFactory::$session = $mockSession;

		$this->object = JAuthentication::getInstance();
		$tester = $this->getDatabaseTester();
		$tester->onSetUp();

		$credentials['username'] = 'admin';
		$credentials['password'] = 'testing';
		$options = array();
		$response = $this->object->authenticate($credentials, $options);

		$this->assertThat(
			true,
			$this->equalTo((bool)$response->status)
		);
	}
開發者ID:realityking,項目名稱:JAJAX,代碼行數:37,代碼來源:JAuthenticationTest.php

示例2: testAuthentication

 /**
  * This checks for the correct Long Version.
  *
  * @return void
  * @dataProvider casesAuthentication
  */
 public function testAuthentication($input, $expect, $message)
 {
     $this->assertEquals($expect, JAuthentication::authenticate($input), $message);
 }
開發者ID:hamanakam1,項目名稱:joomla-platform,代碼行數:10,代碼來源:JAuthenticationTest.php

示例3: login

	/**
	 * Login authentication function.
	 *
	 * Username and encoded password are passed the onUserLogin event which
	 * is responsible for the user validation. A successful validation updates
	 * the current session record with the user's details.
	 *
	 * Username and encoded password are sent as credentials (along with other
	 * possibilities) to each observer (authentication plugin) for user
	 * validation.  Successful validation will update the current session with
	 * the user details.
	 *
	 * @param   array  $credentials  Array('username' => string, 'password' => string)
	 * @param   array  $options      Array('remember' => boolean)
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   11.1
	 */
	public function login($credentials, $options = array())
	{
		// Get the global JAuthentication object.
		jimport('joomla.user.authentication');

		$response = JAuthentication::authenticate($credentials, $options);

		if ($response->status === JAuthentication::STATUS_SUCCESS)
		{
			// validate that the user should be able to login (different to being authenticated)
			// this permits authentication plugins blocking the user
			$authorisations = JAuthentication::authorise($response, $options);
			foreach ($authorisation as $authorisation)
			{
				$denied_states = Array(JAuthentication::STATUS_EXPIRED, JAuthentication::STATUS_DENIED);
				if (in_array($authorisation->status, $denied_states))
				{
					// Trigger onUserAuthorisationFailure Event.
					$this->triggerEvent('onUserAuthorisationFailure', array((array) $authorisation));

					// If silent is set, just return false.
					if (isset($options['silent']) && $options['silent'])
					{
						return false;
					}

					// Return the error.
					switch ($authorisation->status)
					{
						case JAuthentication::STATUS_EXPIRED:
							return JError::raiseWarning('102002', JText::_('JLIB_LOGIN_EXPIRED'));
							break;
						case JAuthentication::STATUS_DENIED:
							return JError::raiseWarning('102003', JText::_('JLIB_LOGIN_DENIED'));
							break;
						default:
							return JError::raiseWarning('102004', JText::_('JLIB_LOGIN_AUTHORISATION'));
							break;
					}
				}
			}

			// Import the user plugin group.
			JPluginHelper::importPlugin('user');

			// OK, the credentials are authenticated and user is authorised.  Lets fire the onLogin event.
			$results = $this->triggerEvent('onUserLogin', array((array) $response, $options));

			/*
			 * If any of the user plugins did not successfully complete the login routine
			 * then the whole method fails.
			 *
			 * Any errors raised should be done in the plugin as this provides the ability
			 * to provide much more information about why the routine may have failed.
			 */

			if (!in_array(false, $results, true))
			{
				// Set the remember me cookie if enabled.
				if (isset($options['remember']) && $options['remember'])
				{
					jimport('joomla.utilities.simplecrypt');
					jimport('joomla.utilities.utility');

					// Create the encryption key, apply extra hardening using the user agent string.
					$key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);

					$crypt = new JSimpleCrypt($key);
					$rcookie = $crypt->encrypt(serialize($credentials));
					$lifetime = time() + 365 * 24 * 60 * 60;

					// Use domain and path set in config for cookie if it exists.
					$cookie_domain = $this->getCfg('cookie_domain', '');
					$cookie_path = $this->getCfg('cookie_path', '/');
					setcookie(JUtility::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, $cookie_path, $cookie_domain);
				}

				return true;
			}
		}

//.........這裏部分代碼省略.........
開發者ID:nikosdion,項目名稱:Akeeba-Example,代碼行數:101,代碼來源:application.php


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