开发者

delete user best practice?

开发者 https://www.devze.com 2022-12-15 03:19 出处:网络
ive got a forum and i allow user to delete their account. and i want the users threads to still be there and the username to be shown, but i wonder one thing.

ive got a forum and i allow user to delete their account.

and i want the users threads to still be there and the username to be shown, but i wonder one thing.

if a user is deleted (basically i just NULL their username and password in the table row but i leave everything else intact) and another user is registering the same username, then people will believe t开发者_如何学Gohat the new user with the same username has created all the threads the previous user created.

or is it routine to not allow new users to pick those usernames who have been deleted?

what is best practice regarding deleting users?


Add an extra column to your users table, called 'deleted' or similar. Default this to zero (false). When the user is "deleted", set this field to 1 (true). That way you won't run across any problems with users having duplicate usernames, as the original will be still present and linked to your existing posts etc.


I would keep a deleted field in the table as a boolean. Set it to true when the user leaves. Keep usernames unique.


Add a DeletedDate column. If this column is NULL, then the user account is not deleted.

This way you are not deleting any data, and you can undelete the account later if you wish, with username, etc. intact.


You should not actually delete users, just set a "deleted" flag on their records in database. If such flag is set, do not allow the user to log in. Also, show the user page with "user is deleted" on it. If you actually delete a record, you will have to decide, what to do with

  • forum posts the user has been authoring
  • replies made by the user
  • replies where someone mentions something said by the deleted user
  • private messages sent to/from this user

So, this would actually change the conversations people have had.


If it's important to enable others to use the old username, you could change user's name into eg. Deleted User X - that way there would still be a connection between the user's posts (which could be important in some cases).


If you keep the posts and the usernames you don't want to people to register the same username again. It will cause a lot of confusion. Typically you also make the username a unique key of the user table.

I would recommend letting the users delete their accounts completely if there are no associated posts or other activity. If there are associated posts the account is disabled and the posts marked as made by "Deleted user".

Then make it an administrative action to wipe the account and associated posts completely. This can be added to your regular maintenance tools.


You can even add an extra column in users table titled "uid" and generate new uid for every new user who registers.


The posts should be linked to user via an ID not by username so unless you reuse an ID, which you shouldn't, then you won't have this problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消