Reputation: 10228
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"
How can I implement that?
Upvotes: 0
Views: 91
Reputation: 179
I don't understand why you are doing this in SQL,
Why not just have the website pull the users data, and based of the active column allow access or deny the the website?
if you are blocking your user from voting, viewing or what ever, based on that field just flick up the error message
When the user signs in, pull all the information you are going to need.
Username, email, image path, active field what ever. store it in the session. and then you never need to query that data again. unless they update it, at which point you change their session data.
Upvotes: 1
Reputation: 3034
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)
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.
Upvotes: 1