简体   繁体   English

如何在网站上实施自动取消禁止? ASP.NET

[英]How to implement auto unban on website? ASP.NET

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. 当足够多的用户标记另一个用户时,该用户将被禁止X倍的时间。 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. 经过X倍的时间后,我要自动取消禁止,并且用户名旁边没有符号。 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. 目前,我唯一想到的解决方案是在isUserBanned()中运行一个检查,以查看如果用户当前被禁止,是否应该取消禁止该用户。

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. 当然,您必须过去将所有人的BannedUntil标志设置为某种方式,或者在其位置处理NULL / Nothing值。

在一个经常运行的数据库上安排一个计划任务,并对照当前日期检查[禁止截止日期],并适当地更新[禁止]标志。

Add fields to your User data to store a DateTime of when they will be unbanned. 将字段添加到您的用户数据中以存储DateTime的禁止时间。 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. 在您的视图代码中,如果该值为NULL或在过去不禁止使用,否则在将来禁止使用。 It's then optional whether to actually clear that "unbanned" DateTime. 然后可以选择是否实际清除该“不受限制的” 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). 显然,您不想手动运行它,因此可以使用cron作业或计划任务(取决于OS)将其自动化。 Having it run once every hour or two would probably be sufficient. 每隔一两个小时运行一次就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM