我有一個像SO這樣的網站。我在所有表格上都有一個觸發器(插入之前的),它檢查用戶的狀態。這樣的事情:如何控制用戶在我的網站上的活動?
// 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;
現在我需要一個案例,禁用他做任何活動。我想知道如何管理所有用戶的活動?並讓他看起來像這樣:
"You are banned and you cannot do any activity"
我該如何實現這一點?
那麼,如果用戶被禁止評論*和*回答,但是不能從其他方面做什麼,你會怎麼做? –
@NiettheDarkAbsol我不能那樣做(禁止*評論*和*回答*)。因爲'active'列只包含一個數字。 '0'他可以做任何事情。 '1'他被禁止*投票*等等...... – stack
好奇。在'if(@ban = 1)'和其他...不應該讀爲'if(@ban == 1)'?但我可能是錯的。 –