本文整理汇总了PHP中JAuthentication类的典型用法代码示例。如果您正苦于以下问题:PHP JAuthentication类的具体用法?PHP JAuthentication怎么用?PHP JAuthentication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JAuthentication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
);
}
示例2: upload
public function upload()
{
$app = JFactory::getApplication();
$this->getInputData();
try {
jimport('joomla.user.authentication');
$auth =& JAuthentication::getInstance();
$credentials = array('username' => $this->username, 'password' => $this->password);
$response = $auth->authenticate($credentials, array());
if ($response->status !== JAUTHENTICATE_STATUS_SUCCESS) {
throw new Exception("Authentification error: {$response->status}");
}
$tmpdir = JPath::clean($app->getCfg("tmp_path"));
if (!JFolder::exists($tmpdir)) {
throw new Exception("Could not open temporary directory");
}
if (!is_array($this->xmlfile)) {
throw new Exception("No xml file found");
}
$xmlpath = $tmpdir . "/" . $this->xmlfile["name"];
if (!JFile::upload($this->xmlfile["tmp_name"], $xmlpath)) {
throw new Exception("Error uploading xml file");
}
$xml = new SimpleXMLElement($xmlpath, 0, true);
$data = array();
$mode = (string) $xml->getName();
foreach ($xml->THE_FIRM as $firm) {
$item = array();
$item["inn"] = (string) $firm["inn"];
$itemDT = DateTime::createFromFormat("d.m.Y H:i:s", (string) $firm->DateTime);
$item["adding_date"] = $itemDT->format("Y-m-d H:i:s");
if ($mode == "AddChange") {
$item["name"] = (string) $firm->Name;
$item["address"] = (string) $firm->Address;
$item["certificate1"] = (string) $firm->Number;
}
$data[$item["inn"]] = $item;
}
$model = $this->getModel("Items", "SroModel");
if (!$model->update($data, $mode)) {
throw new Exception($model->getError());
}
if (is_array($this->docfile)) {
$config = SroHelper::getConfig();
$docpath = $config->get("rootfolder");
$docpath = JPATH_SITE . "/" . JPath::clean($docpath) . "/" . $this->docfile["name"];
if (!JFile::upload($this->docfile["tmp_name"], $docpath)) {
throw new Exception("Error uploading data file");
}
}
} catch (Exception $e) {
if ($this->talk) {
echo $e->getMessage();
}
}
$app->close();
}
示例3: onBeforeBrowse
public function onBeforeBrowse()
{
// If we have a username/password pair, log in the user if he's a guest
$username = $this->input->getString('username', '');
$password = $this->input->getString('password', '');
$user = JFactory::getUser();
if ($user->guest && !empty($username) && !empty($password)) {
JLoader::import('joomla.user.authentication');
$credentials = array('username' => $username, 'password' => $password);
$app = JFactory::getApplication();
$options = array('remember' => false);
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status == JAuthentication::STATUS_SUCCESS) {
JPluginHelper::importPlugin('user');
$results = $app->triggerEvent('onLoginUser', array((array) $response, $options));
JLoader::import('joomla.user.helper');
$userid = JUserHelper::getUserId($response->username);
$user = JFactory::getUser($userid);
$parameters['username'] = $user->get('username');
$parameters['id'] = $user->get('id');
}
}
// If we still have a guest user, show the login page
if ($user->guest) {
// Show login page
$juri = JURI::getInstance();
$myURI = base64_encode($juri->toString());
$com = version_compare(JVERSION, '1.6.0', 'ge') ? 'users' : 'user';
JFactory::getApplication()->redirect(JURI::base() . 'index.php?option=com_' . $com . '&view=login&return=' . $myURI);
return false;
}
// Does the user have core.manage access or belongs to SA group?
$isAdmin = $user->authorise('core.manage', 'com_akeebasubs');
if ($this->input->getInt('allUsers', 0) && $isAdmin) {
$this->getThisModel()->user_id(null);
} else {
$this->getThisModel()->user_id(JFactory::getUser()->id);
}
if ($this->input->getInt('allStates', 0) && $isAdmin) {
$this->getThisModel()->paystate(null);
} else {
$this->getThisModel()->paystate('C,P');
}
// Let me cheat. If the request doesn't specify how many records to show, show them all!
if ($this->input->getCmd('format', 'html') != 'html') {
if (!$this->input->getInt('limit', 0) && !$this->input->getInt('limitstart', 0)) {
$this->getThisModel()->limit(0);
$this->getThisModel()->limitstart(0);
}
}
return true;
}
示例4: getxCredentials
public function getxCredentials()
{
//if (!isset($this->msg))
//{
$this->username = JRequest::getVar('user', '');
$this->password = JRequest::getVar('password', '');
$this->checkParameters();
$auth = JAuthentication::getInstance();
$credentials = array('username' => $this->username, 'password' => $this->password);
JFactory::getApplication()->login(array('username' => $this->username, 'password' => $this->password));
$options = array();
$response = $auth->authenticate($credentials, $options);
return $response;
}
示例5: onAfterInitialise
/**
* Handles the onAfterInitialise event in Joomla!, logging in the user using
* the one time password and forwarding him to the action URL
*/
public function onAfterInitialise()
{
$app = JFactory::getApplication();
// Only fire in administrator requests
if (in_array($app->getName(), array('administrator', 'admin'))) {
// Make sure it's an OneClickAction request
$otp = JFactory::getApplication()->input->getCmd('oneclickaction', '');
if (empty($otp)) {
return;
}
// Check that we do have a table!
self::_checkInstallation();
// Perform expiration control
self::_expirationControl();
// Make sure this OTP exists
$db = JFactory::getDBO();
$sql = $db->getQuery(true)->select('*')->from($db->qn('#__oneclickaction_actions'))->where($db->qn('otp') . ' = ' . $db->q($otp));
$db->setQuery($sql);
$oca = $db->loadObject();
if (empty($oca)) {
return;
}
// Login the user
$user = JFactory::getUser($oca->userid);
JLoader::import('joomla.user.authentication');
$app = JFactory::getApplication();
$authenticate = JAuthentication::getInstance();
$response = new JAuthenticationResponse();
$response->status = JAuthentication::STATUS_SUCCESS;
$response->type = 'joomla';
$response->username = $user->username;
$response->email = $user->email;
$response->fullname = $user->name;
$response->error_message = '';
JPluginHelper::importPlugin('user');
$options = array();
JLoader::import('joomla.user.helper');
$results = $app->triggerEvent('onLoginUser', array((array) $response, $options));
JFactory::getSession()->set('user', $user);
// Delete all similar OCA records
$sql = $db->getQuery(true)->delete($db->qn('#__oneclickaction_actions'))->where($db->qn('actionurl') . ' = ' . $db->q($oca->actionurl));
$db->setQuery($sql);
$db->execute();
// Forward to the requested URL
$app->redirect($oca->actionurl);
$app->close();
}
}
示例6: login
/**
* Logs in the user
*
* @since 1.3
* @access public
* @param string
* @return
*/
public static function login($username, $password)
{
// Get the global JAuthentication object
jimport('joomla.user.authentication');
$auth = JAuthentication::getInstance();
$credentials = array('username' => $username, 'password' => $password);
$options = array();
$app = JFactory::getApplication();
$response = $app->login($credentials);
// Try to authenticate the user with Joomla
if ($response === true) {
$my = JFactory::getUser();
if ($my->guest) {
return new xmlrpcresp(0, 403, JText::_('Login Failed'));
}
return true;
}
return new xmlrpcresp(0, 403, JText::_('Login Failed'));
}
示例7: checkAccount
function checkAccount($username, $password, $email, &$userid, $conf)
{
$app = JFactory::getApplication();
$query = 'SELECT id,username' . ' FROM `#__users`' . ' WHERE email=' . $this->_db->Quote($email);
$this->_db->setQuery($query);
$user = $this->_db->loadObject();
if (isset($user)) {
$credentials = array();
$username = $user->username;
$credentials['username'] = $username;
$credentials['password'] = $password;
jimport('joomla.user.authentication');
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, array());
if (defined('JAUTHENTICATE_STATUS_SUCCESS')) {
define('TAUTHENTICATE_STATUS_SUCCESS', JAUTHENTICATE_STATUS_SUCCESS);
} else {
define('TAUTHENTICATE_STATUS_SUCCESS', JAuthentication::STATUS_SUCCESS);
}
if ($response->status === TAUTHENTICATE_STATUS_SUCCESS) {
$app->login(array('username' => $username, 'password' => $password), array());
$user = JFactory::getUser($username);
$userid = $user->id;
return null;
} else {
//Login Failed
return "bad_password";
}
} else {
$username = $username;
$userid = $this->saveRegistration($conf->comprofiler);
if ($userid == false) {
return "bad_password";
} else {
$app->login(array('username' => $username, 'password' => $password), array());
$user = JFactory::getUser($username);
$userid = $user->id;
}
return null;
}
}
示例8: loadUserByCredentials
public function loadUserByCredentials($user, $pass)
{
jimport('joomla.user.authentication');
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate(array('username' => $user, 'password' => $pass));
if ($response->status === JAuthentication::STATUS_SUCCESS) {
$instance = JUser::getInstance($response->username);
if ($instance === false) {
$this->setError(JError::getError());
return false;
}
} else {
if (isset($response->error_message)) {
$this->setError($response->error_message);
} else {
$this->setError($response->getError());
}
return false;
}
return $instance;
}
示例9: execute
function execute()
{
jimport('joomla.user.authentication');
jimport('joomla.application.component.helper');
// jimport( 'joomla.session.session' );
// jimport('joomla.plugin.plugin');
// jimport( 'plugins.user.joomla.joomla' );
// echo JPATH_BASE;
//require_once ( JPATH_BASE .DS.'plugins'.DS.'user'.DS.'joomla'.DS.'joomla.php' );
// import plugins/user/joomla/joomla.php;
//import libraries/joomla/application/component/helper.php
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$mainframe->login();
$auth = JAuthentication::getInstance();
$credentials = array('username' => $this->username, 'password' => $this->password);
JFactory::getApplication()->login(array('username' => $this->username, 'password' => $this->password));
//print_r($credentials);
$options = array();
$response = $auth->authenticate($credentials, $options);
//$response = $auth->authenticate($result, $options);
// $session =& JFactory::getSession();
//$myUser = $session->get( 'myUser', 'empty' );
//$session =& JFactory::getSession();
//$session->set( 'myvar', 'helloworld' );
//onUserLogin::onUserLogin();
//var_dump($session);exit();
echo json_encode($response);
echo $response->status;
// echo JAUTHENTICATE_STATUS_SUCCESS;
//print_r($response);
// success
/* return ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
$response->status = true;
} else {
// failed
$response->status = false;
}
echo json_encode($response);*/
}
示例10: vmCheckPass
/**
* Login validation function
*
* Username and encoded password is compared to db entries in the mos_users
* table. A successful validation returns true, otherwise false
*/
function vmCheckPass()
{
global $database, $perm, $my, $mainframe;
// only allow access to admins or storeadmins
if ($perm->check("admin,storeadmin")) {
$username = $my->username;
$passwd_plain = $passwd = trim(vmGet($_POST, 'passwd', ''));
if (empty($passwd_plain)) {
$GLOBALS['vmLogger']->err('Password empty!');
return false;
}
$passwd = md5($passwd);
$bypost = 1;
if (!$username || !$passwd || $_REQUEST['option'] != "com_virtuemart") {
return false;
} elseif (vmIsJoomla('1.5')) {
$credentials = array();
$credentials['username'] = $username;
$credentials['password'] = $passwd_plain;
$options = array();
jimport('joomla.user.authentication');
$authenticate =& JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
return true;
} else {
return false;
}
} else {
if (vmIsJoomla('1.0.12', '<=', false)) {
$database->setQuery("SELECT id, gid, block, usertype" . "\nFROM #__users" . "\nWHERE username='{$username}' AND password='{$passwd}'");
$row = null;
$res = $database->loadObject($row);
} else {
$query = "SELECT id, name, username, password, usertype, block, gid" . "\n FROM #__users" . "\n WHERE username = " . $database->Quote($username);
$database->setQuery($query);
$row = null;
$database->loadObject($row);
list($hash, $salt) = explode(':', $row->password);
$cryptpass = md5($passwd_plain . $salt);
$res = $hash == $cryptpass;
}
if ($res) {
return true;
} else {
$GLOBALS['vmLogger']->err('The Password you\'ve entered is not correct for your User Account');
return false;
}
}
}
return false;
}
示例11: _actionAdd
/**
* Authenticate a person and create a new session If a username password is passed then the user is first logged in.
*
* @param KCommandContext $context Command chain context
*
* @throws LibBaseControllerExceptionUnauthorized If authentication failed
* @throws LibBaseControllerExceptionForbidden If person is authenticated but forbidden
* @throws RuntimeException for unkown error
*/
protected function _actionAdd(KCommandContext $context)
{
$data = $context->data;
if ($data->return) {
$_SESSION['return'] = $this->getService('com://site/people.filter.return')->sanitize($data->return);
$context->url = base64UrlDecode($data->return);
} else {
$_SESSION['return'] = null;
}
jimport('joomla.user.authentication');
$authentication =& JAuthentication::getInstance();
$credentials = array('username' => $data->username, 'password' => $data->password, 'remember' => $data->remember);
$options = array();
$authResponse = $authentication->authenticate($credentials, $options);
if ($authResponse->status === JAUTHENTICATE_STATUS_SUCCESS) {
$this->getService('com:people.helper.person')->login($credentials, $credentials['remember']);
$this->getResponse()->status = KHttpResponse::ACCEPTED;
$this->getResponse()->setRedirect($context->url);
$_SESSION['return'] = null;
} else {
$this->setMessage('COM-PEOPLE-AUTHENTICATION-FAILED', 'error');
JFactory::getApplication()->triggerEvent('onLoginFailure', array((array) $authResponse));
throw new LibBaseControllerExceptionUnauthorized('Authentication Failed. Check username/password');
$this->getResponse()->status = KHttpResponse::FORBIDDEN;
$this->getResponse()->setRedirect(JRoute::_('option=com_people&view=session'));
}
return true;
}
示例12: loginUser
/**
* logs in a user
*
* @param array $authInfo authentification information
*
* @return boolean True on success
*/
public function loginUser($authInfo)
{
\JLoader::import('joomla.user.authentication');
$options = array('remember' => false);
$authenticate = \JAuthentication::getInstance();
$response = $authenticate->authenticate($authInfo, $options);
// User failed to authenticate: maybe he enabled two factor authentication?
// Let's try again "manually", skipping the check vs two factor auth
// Due the big mess with encryption algorithms and libraries, we are doing this extra check only
// if we're in Joomla 2.5.18+ or 3.2.1+
if ($response->status != \JAuthentication::STATUS_SUCCESS && method_exists('JUserHelper', 'verifyPassword')) {
$db = \JFactory::getDbo();
$query = $db->getQuery(true)->select('id, password')->from('#__users')->where('username=' . $db->quote($authInfo['username']));
$result = $db->setQuery($query)->loadObject();
if ($result) {
$match = \JUserHelper::verifyPassword($authInfo['password'], $result->password, $result->id);
if ($match === true) {
// Bring this in line with the rest of the system
$user = \JUser::getInstance($result->id);
$response->email = $user->email;
$response->fullname = $user->name;
if (\JFactory::getApplication()->isAdmin()) {
$response->language = $user->getParam('admin_language');
} else {
$response->language = $user->getParam('language');
}
$response->status = \JAuthentication::STATUS_SUCCESS;
$response->error_message = '';
}
}
}
if ($response->status == \JAuthentication::STATUS_SUCCESS) {
$this->importPlugin('user');
$results = $this->runPlugins('onLoginUser', array((array) $response, $options));
unset($results);
// Just to make phpStorm happy
\JLoader::import('joomla.user.helper');
$userid = \JUserHelper::getUserId($response->username);
$user = $this->getUser($userid);
$session = \JFactory::getSession();
$session->set('user', $user);
return true;
}
return false;
}
示例13: captiveLogin
/**
* Checks the super admin credentials are valid for the currently logged in users
*
* @param array $credentials The credentials to authenticate the user with
*
* @return bool
*
* @since 3.6.0
*/
public function captiveLogin($credentials)
{
// Make sure the username matches
$username = isset($credentials['username']) ? $credentials['username'] : null;
$user = JFactory::getUser();
if ($user->username != $username) {
return false;
}
// Make sure the user we're authorising is a Super User
if (!$user->authorise('core.admin')) {
return false;
}
// Get the global JAuthentication object.
jimport('joomla.user.authentication');
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials);
if ($response->status !== JAuthentication::STATUS_SUCCESS) {
return false;
}
return true;
}
示例14: authenticateUser
function authenticateUser($username, $password)
{
// Get the global JAuthentication object
jimport('joomla.user.authentication');
$auth =& JAuthentication::getInstance();
$credentials = array('username' => $username, 'password' => $password);
$options = array();
$response = $auth->authenticate($credentials, $options);
//TODO CHECK that registred users do not have access
//$user =& JFactory::getUser($username);
//plgXMLRPCOpenERP2VmHelper::getUserAid( $user );
return $response->status === JAUTHENTICATE_STATUS_SUCCESS;
}
示例15: login
/**
* Login authentication function.
*
* Username and encoded password are passed the the onLoginUser event which
* is responsible for the user validation. A successful validation updates
* the current session record with the users 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 Array( 'username' => string, 'password' => string )
* @param array Array( 'remember' => boolean )
* @return boolean True on success.
* @access public
* @since 1.5
*/
function login($credentials, $options = array())
{
// Get the global JAuthentication object
jimport('joomla.user.authentication');
$authenticate =& JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
$session =& JFactory::getSession();
// we fork the session to prevent session fixation issues
$session->fork();
$this->_createSession($session->getId());
// Import the user plugin group
JPluginHelper::importPlugin('user');
// OK, the credentials are authenticated. Lets fire the onLogin event
$results = $this->triggerEvent('onLoginUser', 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
$agent = @$_SERVER['HTTP_USER_AGENT'];
// Ignore empty and crackish user agents
if ($agent != '' && $agent != 'JLOGIN_REMEMBER') {
$key = JUtility::getHash($agent);
$crypt = new JSimpleCrypt($key);
$rcookie = $crypt->encrypt(serialize($credentials));
$lifetime = time() + 365 * 24 * 60 * 60;
setcookie(JUtility::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, '/');
}
}
return true;
}
}
// Trigger onLoginFailure Event
$this->triggerEvent('onLoginFailure', array((array) $response));
// If silent is set, just return false
if (isset($options['silent']) && $options['silent']) {
return false;
}
// Return the error
return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_AUTHENTICATE'));
}