Delete unconfirmed accounts after 12 hours

This commit is contained in:
rubenwardy 2021-11-24 22:54:35 +00:00
parent bc371f1ef3
commit c0eb10521d
4 changed files with 20 additions and 7 deletions

@ -280,3 +280,11 @@ def import_licenses():
db.session.add(obj)
db.session.commit()
@action("Delete inactive users")
def delete_inactive_users():
users = User.query.filter(User.is_active==False, User.packages==None, User.forum_topics==None, User.rank==UserRank.NOT_JOINED).all()
for user in users:
db.session.delete(user)
db.session.commit()

@ -25,12 +25,12 @@ There are a number of reasons this may have happened:
* Email has been unsubscribed.
If the email doesn't arrive after registering by email, then you'll need to try registering again in 12 hours.
Unconfirmed accounts are deleted every 12 hours.
Unconfirmed accounts are deleted after 12 hours.
If the email verification was sent using the Email settings tab, then you can just set a new email.
If you have previously unsubscribed this email, then ContentDB is completely prevented from sending emails to that
address. You'll need to use a different email address, or [contact an admin](https://rubenwardy.com/contact/) to
address. You'll need to use a different email address, or [contact rubenwardy](https://rubenwardy.com/contact/) to
remove your email from the blacklist.

@ -87,13 +87,13 @@ CELERYBEAT_SCHEDULE = {
'schedule': crontab(minute=0, hour=14), # 1400
},
'delete_inactive_users': {
'task': 'app.tasks.users.delete_inactive_users',
'task': 'app.tasks.usertasks.delete_inactive_users',
'schedule': crontab(minute=15), # every hour at quarter past
},
}
celery.conf.beat_schedule = CELERYBEAT_SCHEDULE
from . import importtasks, forumtasks, emails, pkgtasks, celery
from . import importtasks, forumtasks, emails, pkgtasks, usertasks
# noinspection PyUnusedLocal

@ -16,11 +16,16 @@
import datetime
from app.models import User
from app.models import User, db, UserRank
from app.tasks import celery
@celery.task()
def delete_inactive_users():
threshold = datetime.datetime.now() - datetime.timedelta(hours=12)
User.query.filter(User.is_active==False, User.packages==None, User.created_at<=threshold).delete()
threshold = datetime.datetime.now() - datetime.timedelta(hours=5)
users = User.query.filter(User.is_active==False, User.packages==None, User.forum_topics==None, User.created_at<=threshold, User.rank==UserRank.NOT_JOINED).all()
for user in users:
db.session.delete(user)
db.session.commit()