From c0eb10521d28b4bb1b5c408f1f7c1ba9826107b9 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 24 Nov 2021 22:54:35 +0000 Subject: [PATCH] Delete unconfirmed accounts after 12 hours --- app/blueprints/admin/actions.py | 8 ++++++++ app/flatpages/help/faq.md | 4 ++-- app/tasks/__init__.py | 4 ++-- app/tasks/usertasks.py | 11 ++++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/blueprints/admin/actions.py b/app/blueprints/admin/actions.py index 5c5d795..b6a88ef 100644 --- a/app/blueprints/admin/actions.py +++ b/app/blueprints/admin/actions.py @@ -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() \ No newline at end of file diff --git a/app/flatpages/help/faq.md b/app/flatpages/help/faq.md index 54ef910..6713647 100644 --- a/app/flatpages/help/faq.md +++ b/app/flatpages/help/faq.md @@ -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. diff --git a/app/tasks/__init__.py b/app/tasks/__init__.py index 0e154ed..c945bd9 100644 --- a/app/tasks/__init__.py +++ b/app/tasks/__init__.py @@ -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 diff --git a/app/tasks/usertasks.py b/app/tasks/usertasks.py index 7fb7594..f15c728 100644 --- a/app/tasks/usertasks.py +++ b/app/tasks/usertasks.py @@ -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()