session_insert.sql 295 B

12345678910111213
  1. DROP TRIGGER IF EXISTS `session_insert`;
  2. CREATE TRIGGER `session_insert`
  3. BEFORE INSERT ON `sessions`
  4. FOR EACH ROW BEGIN
  5. IF new.u_id NOT IN (
  6. SELECT id
  7. FROM users
  8. WHERE active = 1
  9. ) THEN
  10. SIGNAL SQLSTATE '45000'
  11. SET MESSAGE_TEXT = 'Cannot create a session for this user';
  12. END IF;
  13. END;