First time here? Check out the FAQ!
1

Spambot registrered 1000 users - command to delete last 1000 users?
 

Some spambot has registrered 1000 users over the last month, is there some command to delete the last 1000 users at once? For example, a SQL command that deletes the content after some date?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
kristof's avatar
51
kristof
asked 10 years ago, updated 10 years ago

Comments

see more comments

2 Answers

1

what type of database you use ???

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Sindbad's avatar
23
Sindbad
answered 10 years ago
link

Comments

postgresql

kristof's avatar kristof (10 years ago)

No. To do it just once you would simply write the delete statement for the table you want to cascade. DELETE FROM some_child_table WHERE some_fk_field IN (SELECT some_id FROM some_Table); DELETE FROM some_table;

Sindbad's avatar Sindbad (10 years ago)
see more comments
1

Firstly, to prevent future spam enable "premoderation" in the settings -> content moderation section. Enable required email confirmation, this will reduce number of spammers at the site.

Answering your question: Delete users via the django shell. (Note: Before doing this back up your database)

Suppose that the last non-spammer user has id number 256

python manage.py shell
>>> from askbot.models import User
>>> users = User.objects.filter(id__gt=256)
>>> users.delete()
>>> exit()

This will delete the users and all the content they have posted.

Another option is to delete all content and block users (this will mark the content as deleted):

 #select the users as above
 >>> admin = User.objects.get(id=1) #assuming that admin has user id 1
 >>> for user in users:  #iterate through users that you want to block/delete
 ...     admin.delete_all_content_authored_by_user(user) #mark all content as deleted
 ...     user.set_status('b') #block user
 ...     user.save()
 >>> exit()

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 10 years ago, updated 10 years ago
link

Comments

see more comments