Page 1 of 1
Notifications module - V2 alternatives? Sends email on event
Posted: Wed May 18, 2016 10:12 pm
by paulbaker
I use the notifications module on every V1 site. It's great, it notifies me by email every time an admin logs in to the backend. So I can easily see which clients are updating their sites - and which are not. It also emails me on every unsuccessful backend login (e.g. wrong password) so I can tell if someone, or something, is trying to hack in.
I would like to continue using it in V2 but it hasn't been updated in a while and it is unlikely to be updated because it was created by a couple of guys who have left the CMSMS world:
http://dev.cmsmadesimple.org/projects/notifications
I tried installing in to a V 2.1.3 site - it seemed to install without error but unsurprisingly it did not work, giving a white unstyled page when accessing the admin page.
Is there an alternative method of getting the functionality described without using this module?
Thanks
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Wed May 18, 2016 10:14 pm
by Rolf
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Wed May 18, 2016 11:09 pm
by paulbaker
Thanks for the swift reply Rolf!
I tried the Mail UDT. It worked great. So I am now notified on a failed login.
I made a similar UDT and linked it to the LoginPost event, hoping to be told every time someone successfully logs in. The UDT fires OK but the $_POST["username"] field is blank. It would be great if anyone had some ideas on that.
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Thu May 19, 2016 7:07 am
by Rolf
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Thu May 19, 2016 8:23 am
by velden
LoginPost
Description: Sent after a user logs into the Admin panel
Parameters
'user' - Reference to the affected user object.
Event Handlers
None
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Thu May 19, 2016 10:00 am
by velden
Generic (for both failed en success):
Code: Select all
$to = 'YOUREMAIL@YOURDOMAIN.COM';
$headers = 'From: CMS Made Simple website.com <noreply@website.com>';
$user = $params['user'];
if ($params['_eventname'] == 'LoginPost') {
$subject = 'Successful login: ' . $user->username . ' - ' . cms_utils::get_real_ip();
$message_template =<<<'EOD'
There has been a successful login in your admin panel.
Username: %s
IP Address: %s
First Name: %s
Last Name: %s
Email %s
EOD;
$message = sprintf($message_template,
$user->username,
cms_utils::get_real_ip(),
$user->firstname,
$user->lastname,
$user->email
);
} elseif($params['_eventname'] == 'LoginFailed') {
$subject = 'Failed login: ' . $user . ' - ' . cms_utils::get_real_ip();
$message_template =<<<'EOD'
There has been a failed login in your admin panel.
Username: %s
IP Address: %s
EOD;
$message = sprintf($message_template,
$user,
cms_utils::get_real_ip()
);
}
@mail($to, $subject, $message, $headers);
Personally I'd rather use the CMSMS api to send the email out (instead of 'mail') but don't have time now to find out how.
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Thu May 19, 2016 2:08 pm
by calguy1000
in 2.x:
$mailer = new cms_mailer();
$mailer->SetSubject($subject);
$mailer->SetBody($body);
$mailer->AddAddress($email_address);
$mailer->Send();
Re: Notifications module - V2 alternatives? Sends email on e
Posted: Sun Oct 23, 2016 7:52 pm
by Rolf