From 8da92e69195750cb5cccfeee53f24459fd14d83c Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 24 Nov 2021 10:39:10 -0800 Subject: [PATCH] add some commands to list and wipe users to remove spammers --- wowstash/cli.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/wowstash/cli.py b/wowstash/cli.py index e2d35eb..a6e761d 100644 --- a/wowstash/cli.py +++ b/wowstash/cli.py @@ -3,7 +3,7 @@ from flask import Blueprint, url_for import wowstash.models from wowstash.library.docker import docker -from wowstash.models import User, PasswordReset +from wowstash.models import User, PasswordReset, Event from wowstash.factory import db, bcrypt @@ -25,6 +25,29 @@ def reset_wallet(user_id): def init(): db.create_all() +@bp.cli.command('list_users') +def list_users(): + users = User.query.all() + for i in users: + print(f'{i.id} - {i.email}') + +@bp.cli.command('wipe_user') +@click.argument('user_id') +def wipe_user(user_id): + user = User.query.get(user_id) + if user: + events = Event.query.filter(Event.user == user.id) + for i in events: + print(f'[+] Deleting event {i.id} for user {user.id}') + db.session.delete(i) + print(f'[+] Deleting user {user.id}') + db.session.delete(user) + db.session.commit() + return True + else: + print('That user id does not exist') + return False + @bp.cli.command('reset_password') @click.argument('user_email') @click.argument('duration')