How do i auto remove a ban on my website? When enough users flag another user that user will be banned for an X amount of time. Then there is a symbol next to the user name showing he is banned (on all his post, not just profile page). After the X amount of time i want to auto unban and have no sybol next to the username. Whats a nice way of doing this? currently the only solution i can think of is to run a check in isUserBanned() to find if the user should be unban if the user is currently bannned.
Have a scheduled task on the database that runs every so often and checks the [banned until date], against the current date and update the [banned] flag as appropiate.
Implement the flag as a "Banned until" date/time setting.
Then instead of removing the ban-value, it will simply start being in the past when the ban is over.
So instead of this type of check:
IF User.IsBanned THEN
You have this:
IF User.BannedUntil <= Now() THEN
Of course, you'd have to either set everyones BannedUntil flag to something way in the past, or handle NULL/Nothing values in its place.
Add fields to your User data to store a DateTime of when they will be unbanned. In your view code, if the value is NULL or in the past they are not banned, otherwise if it's in the future they are banned. It's then optional whether to actually clear that "unbanned" DateTime.
To make it more real time you could have a script which checks for banned users and determines if their time is up.
Obviously you wouldn't want to run this manually so you could automate it using a cron job or scheduled task (OS dependent). Having it run once every hour or two would probably be sufficient.