I want my users to get an email when they login for the first time.
I am thinking to create an array to store userids that have logged in before. When users login, compare their userid with the array, if it is in the array then do nothing, if not then add the id into the array and proceed to generate email.
The question is, where is the best place to do this comparison?
I am thinking it should be right after a user logs in and find this onUserAfterLogin
event on https://docs.joomla.org/Plugin/Events/User. But how do I use it? And should I categorize what I want to do as a plugin?
1 Answer
Yes, writing a plugin and leveraging the onUserAfterLogin
event seems like the best way.
As for how to check for the first visit:
You can check the user's
lastvisitDate
column for a0000-00-00 00:00:00
value as discussed in this Joomla Forum Thread: First login redirect plugin. However, if there was an error in delivering the email, you will need to add a consideration for how you want to be alerted of the failure.You can create a new database table where you keep a record of all successfully emailed users. Then from the plugin, query that table for the user's id, if the row exists you never email again, if the email delivery fails don't add them to the list.
-
onUserAfterLogin is definetly the best way. OP should also go for option 1.. There is no need for a database table. I have this working without problems. A failure of the email sending will normaly not be detected by Joomla anyway, once it is set up correctly. So there needs to be only a notification to an admin if the whole setup is wrong.. Oct 7, 2018 at 20:28