如何控制用户在我网站上的活动? [英] How to control user's activity in my website?

查看:37
本文介绍了如何控制用户在我网站上的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像 SO 这样的网站.我在所有表(插入前)上都有一个触发器,用于检查用户的状态.像这样:

I have a website like SO. I have a trigger on the all tables (before insert) which checks user's status. Something like this:

// this line exists at the top of all triggers
@ban := select ban from user where id = new.current_id;
// new.current_id = $_SESSION['id']

// on the vote table
if ( @ban = 1 ) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You cannot give vote";
endif;

// on the comment table
if ( @ban = 2 ) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You cannot write comment";
endif;

// on the answer table
if ( @ban = 3 ) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You cannot write answer";
endif;

// on the flag table
if ( @ban = 4 ) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You cannot flag";
endif;

// on the favorite table
if ( @ban = 5 ) then
     SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "You cannot favorite";
endif;

现在我需要一个案例来禁止他做任何活动.我想知道如何管理所有用户的活动?然后给他看这样的东西:

Now I need a case to disable him to do any activity. I want to know how can I manage all user's activities? And show him something like this:

"You are banned and you cannot do any activity"

我该如何实现?

推荐答案

您需要创建一个连接表,而不是将禁令存储在用户表的一列中.

You need to create a join table, instead of storing the ban in one column within the user table.

因此,您需要以下表格(为简单起见,仅包含相关列):

So, you would want the following tables (only including relevant columns for simplicity):

USER (ID int, NAME varchar) 

BAN (ID int, NAME varchar)

User_Bans (UserID int, BanID int)

然后,您可以从 User_Bans 表中选择 BanID,并适当地连接消息/禁用功能.如果您有任何问题,请告诉我.

Then, you can select the BanIDs from the User_Bans table and concatenate messages/disable functionality appropriately. Please let me know if you have any questions.

这篇关于如何控制用户在我网站上的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆