Joomla JUser getinstance问题

时间:2010-05-24 17:03:01

标签: plugins joomla joomla1.5

我正在尝试制作身份验证插件。 JUser::getInstance()接受一个输入,它应该是id。有没有办法让一个用户的实例使用其他一些标识符?例如用户名,电子邮件等。

2 个答案:

答案 0 :(得分:1)

可能没有这样的方法。但是,如果您确定用户名或电子邮件是唯一的,那么您可以在libraries / joomla / user /中修改文件user.php并在那里添加方法。

getInstanceByEmail($email)
{
     $query = "select id from jos_users where email=".email;
     // use the code to get the id;
    return getInstance($id);
} // this is just a sample code of how it can be achieved

答案 1 :(得分:0)

由于Joomla自己的身份验证是通过检查用户的用户名(当然还有密码)来完成的,因此它必须是唯一的。是的,你可以做类似@Rixius建议的事情。

这是我的版本:

    // Get a database object
    $db     = JFactory::getDbo();
    $query  = $db->getQuery(true);

    $query->select('id, password');
    $query->from('#__users');
    $query->where('username=' . $db->Quote($credentials['username']));

    $db->setQuery($query);
    $result = $db->loadObject();
    $user = JFactory::getUser();

    if ($result)
    {
        $user = JUser::getInstance($result->id);
    }