简体   繁体   中英

Joomla component : override login action?

I would like to override the login method in my own Joomla component to get login and password.

I'm used Wordpress in which he simply add an action like add_action('my_action', 'my_function')...

How can I get the login method in 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.

To add custom code AFTER authentication, write a User Plugin (See Plugin/Events/User ) and use one of the events that fire there.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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