简体   繁体   English

Joomla组件:覆盖登录操作?

[英]Joomla component : override login action?

I would like to override the login method in my own Joomla component to get login and password. 我想在我自己的Joomla组件中覆盖login方法以获得登录名和密码。

I'm used Wordpress in which he simply add an action like add_action('my_action', 'my_function')... 我用过Wordpress,在其中他只是添加了一个类似add_action('my_action','my_function')的动作...

How can I get the login method in Joomla? 如何在Joomla中获得登录方法? I do not know or find ... 我不知道或找不到...

Thanks for help. 感谢帮助。

You can login with this: 您可以使用以下方式登录:

$app = JFactory::getApplication('site');
$credentials = array(
    'username' => 'someusername',
    'password' => 'somepassword'
);
if(!$app->login($credentials)){
    echo 'Logged in';
}else{
    echo 'Not logged in';
}
$app->logout();    // Log out with this
$app->close();     // Close the app

To add custom code to the login process, you can write a simple User Authentication plugin. 要将自定义代码添加到登录过程中,您可以编写一个简单的用户身份验证插件。 (See Creating an Authentication Plugin for Joomla ) and put your code in the onAuthenticate() function. (请参阅为Joomla创建身份验证插件 ),然后将代码放入onAuthenticate()函数中。

To add custom code AFTER authentication, write a User Plugin (See Plugin/Events/User ) and use one of the events that fire there. 要在身份验证后添加自定义代码,请编写一个用户插件(请参见Plugin / Events / User )并使用在那里触发的事件之一。

The best way to achieve this is to write a plugin. 实现此目的的最佳方法是编写一个插件。 Whether you write an authentication or user plugin depends on your needs. 是否编写身份验证或用户插件取决于您的需求。 Both will give you access to the data you are requesting. 两者都可以使您访问所请求的数据。 Since an authentication plugin is geared towards using an alternate source to authenticate users, I would recommend going with a user plugin. 由于身份验证插件旨在使用备用源来对用户进行身份验证,因此我建议使用用户插件。

<?php
defined('_JEXEC') or die;

class plgUserCustom extends JPlugin
{
    /**
     * This method should handle any login logic and report back to the subject
     *
     * @param   array  $user     Holds the user data
     * @param   array  $options  Array holding options (remember, autoregister, group)
     *
     * @return  boolean  True on success
     *
     * @since   1.5
     */
    public function onUserLogin($user, $options) 
    {

        // Here you can access the un-encrypted POST data using the 
        // $user parameter
        return true;
    }

}

There a lot more which can be done, such as mmodifying the default form and adding/manipulating data both before and after user save events. 还有很多事情可以做,例如修改默认表单以及在用户保存事件之前和之后添加/处理数据。 I attached some links regarding plugins for further reading as well. 我还附上了一些有关插件的链接,以供进一步阅读。

Good Luck! 祝好运!

http://docs.joomla.org/Plugin/Events/User http://docs.joomla.org/Plugin http://docs.joomla.org/Plugin/Events/用户 http://docs.joomla.org/Plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM