Auto-disable user
5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: September 5, 2019 (RSS)
Hello,
I would like to automatically disable a user's account if they do not login for 6 months. I am using the Website Membership plugin and was wondering if there was a system field for lastLoginDate or similar that I could use. I would then create a function that is triggered daily by cron.
Any suggestions?
Thanks as always,
Greg
By daniel - September 3, 2019
Hi Greg,
For this, I would probably use the expiresDate field, as it already handles the functionality of disabling a user after a certain date. You could then add some code to your header that checks for a valid user, and if one exists, then update expiresDate to be 6 months in the future.
Let me know if you think that could work for you, or if you have any questions!
Thanks,
Technical Lead
interactivetools.com
By daniel - September 3, 2019
A quick note that it looks like the expiry functionality may be disabled by default for WebsiteMembership logins. To enable, look in websiteMembership.php for a line containing this code (Line 121 in the latest version):
if (@$CURRENT_USER['isExpired']) { alert(t("Your account has expired.")); }
And uncomment it if it isn't already.
Technical Lead
interactivetools.com
Hi Daniel,
Thanks for the suggestion. I guess there are a number of ways I could do this...
I'm currently thinking I could just take the lastLoginDate from the accounts table and do something like this on a daily cron?
select * from cmsb_accounts where accounts.lastLoginDate > 6 months and set accounts.disabled = 1
Thanks,
Greg
By daniel - September 5, 2019
Hi Greg,
Yes, I think something like that would also work. It'd be particularly useful if you want an easy way to check for disabled users, rather than having to compare the expiry date. Otherwise, both solutions are going to be roughly equivalent, other than one requiring cron setup.
Good luck getting this working - let me know if you need any more help!
Thanks,
Technical Lead
interactivetools.com