簡體   English   中英

從控制器方法登錄joomla 2.5

[英]joomla 2.5 login from a conroller method

 public function login()
{

    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query="SELECT * FROM #__users WHERE fb_id=".$_REQUEST['val'];
    $db->setQuery($query);
    $row = $db->loadRow();
    if(count($row)>0 and is_array($row))
    {       
        jimport('joomla.user.helper');
        $salt = JUserHelper::genRandomPassword(32);
        $crypt = JUserHelper::getCryptedPassword($_REQUEST['val'], $salt);
        $password = $crypt.':'.$salt;
        $query="UPDATE #__users SET password = '".$password."' WHERE fb_id =".$_REQUEST['val'];
        $db->setQuery($query);
        $db->query();
        $credentials = array( 'username' => $row[2], 'password' => $password);
        $login_site =JFactory::getApplication();
        $login_site->login($credentials, $options=array());
    }
    header("location:".JURI::base());
}

我在\\ components \\ com_users \\ controller.php中聲明了此方法,但是每次登錄時身份驗證都失敗,重定向用戶保持相同狀態后。請提前幫助。

這段代碼對我有用。

<?php define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');

$credentials = array();
$credentials['username'] = //your userid;
$credentials['password'] = //your password;

//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
print_r($user );
//now you are logged in
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM