[SOLVED] Delete user who didn't complete registration

Good evening.
I have a Plone site:

  • Plone 4.3.7 (4311)
  • CMF 2.2.9
  • Zope 2.13.23
  • Python 2.7.8 (default, Nov 26 2014, 13:28:10) [GCC 4.8.2]
  • PIL 1.1.7

The registration confirmation mechanism forces the user to respond to a "Confirm Registration" email sent after successful registration to verify his email address and activate their account. The user does this by clicking a unique activation link sent to them over email.

I have a lot of users who didn't complete their registration, because they hadn't clicked the activation link.
How could I delete them?
I've tried with:
killuser = api.user.get(username=user_id)
api.user.delete(user=killuser)
but it takes a lot of time.
I read this:
"Deleting the local roles is what takes up the memory: it goes through the whole site, waking up all objects, which can be a lot if you have a big site".
I really don't need to take care of objects, because I'm sure that these users haven't any object.

I've tried this:
def remove_subscriber(self, email):
"""Remove subscriber. We can not use api.user.delete as, by
default, it tries to remove member areas and local roles; the
later consumes a lot of memory and is not necessary for us.
"""
membership_tool = api.portal.get_tool('portal_membership')
with api.env.adopt_roles(['Manager']):
membership_tool.deleteMembers(
[email], delete_memberareas=False, delete_localroles=False)

from Alternate way do delete users
but without success.

Something like https://github.com/plone/Products.CMFPlone/blob/56d33f2c6b9ccb95456d54729f11c63e308de6c7/Products/CMFPlone/controlpanel/browser/usergroups_usersoverview.py#L227-L237 should do

It works!
Thank you!

Plone Foundation Code of Conduct