0

I am trying to create a plugin to make some database queries from the event onUserAuthorisation. Right now I am just trying to set up a "Hello World" style plugin, because I am not sure yet that my plugin function is even firing correctly. Right now the plugin should just send out an email when a new user gains authorisation.

I can confirm that the joomla emails work for user registration and administration.

Files: autoextranet.php,autoextranet.xml,index.html(empty)

autoextranet.php

<?php

// no direct access
defined('_JEXEC') or die;

class plgUserAutoextranet extends JPlugin
{
    public function onUserAuthorisation($user, $options)
        {
        $mailer = JFactory::getMailer();
        $config = JFactory::getConfig();

        $sender = array( 
            $config->get( 'mailfrom' ),
            $config->get( 'fromname' )
            );
        $mailer->setSender($sender);

        $recipient = array( 'email1@gmail.com', 'email2@some.com' );
        $mailer->addRecipient($recipient);

        $body = "New User: ".$user->username;
        $mailer->setBody($body);

        $mailer->setSubject('You got a new user.');

        $mailer->Send();
        }
}

?>

autoextranet.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.8.2" type="plugin" group="user">
        <name>PLG_USER_AUTOEXTRANET</name>
        <author>Tim DeLise</author>
        <creationDate>Nov 14, 2017</creationDate>
        <copyright>Tim D</copyright>
        <license>GNU General Public License</license>
        <authorEmail>your email</authorEmail>
        <authorUrl>your website</authorUrl>
        <version>1.0</version>
        <description>.</description>
        <files>
                <filename plugin="autoextranet">autoextranet.php</filename>
                <filename>index.html</filename>
        </files>
</extension>

The problem now is that I have installed and activated the plugin. When I create and activate a new user, I just get nothing.

Unfortunately I have limited access to the server, and haven't been able to view the PHP error logs. I am looking for some way to confirm that the event is firing my code. Any suggestion is welcome. Also this is the first plugin I am making so maybe there is something wrong with my files.

Any help is greatly appreciated.

Joomla Version 3.8.2

  • Are you certain the onUserAuthorisation hook is being called? – David Hayes Nov 15 '17 at 17:14
  • @DavidHayes no, i guess not. I figured it was from the description: The system triggers this event after the user has been authenticated and before he has been signed in the website. I am trying to trigger it by creating a new user and activating then using the email link. – jeffery_the_wind Nov 15 '17 at 20:38
  • I've run into issues before where my hook wasn't called. I would try putting a "echo 'inside'; exit;" right inside the onUserAuthorisation method then try to login just to verify it is called. – David Hayes Nov 15 '17 at 20:41
  • Also, the Joomla docs (docs.joomla.org/Plugin/Events/User) on the onUserAuthorisation method mention this plugin as an example (github.com/ITPrism/Plugin-User-FaceControl). Coincidentally, it implements the exact functionality you are working on. – David Hayes Nov 15 '17 at 20:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.