Show
Ignore:
Timestamp:
08/05/2008 10:44:02 PM (4 months ago)
Author:
Shadowhand
Message:

Fixing issues with Auth, see http://forum.kohanaphp.com/comments.php?DiscussionID=763, this should have been committed after r3253

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/auth/views/auth/install.php

    r2441 r3267  
    1 <p>The following tables must be installed in your database: users, roles, and users_roles. If you have not already installed these tables, please run the following query:</p> 
     1<div class="box"> 
    22 
    3 <pre> 
     3<p>The following tables must be installed in your database: <code>users</code>, <code>roles</code>, <code>roles_users</code>, and <code>user_tokens</code>. If you have not already installed these tables, please run the installation query below.</p> 
     4 
     5<p>After the tables have been installed, <?php echo html::anchor('auth_demo/create', 'create a user') ?>.</p> 
     6 
     7<p><em>This query is MySQL-specific, but should be easy to adapt to an database that supports foreign keys.</em></p> 
     8 
     9<?php echo form::textarea('query', <<<EOF 
    410CREATE TABLE IF NOT EXISTS `roles` ( 
    511  `id` int(11) unsigned NOT NULL auto_increment, 
     
    814  PRIMARY KEY  (`id`), 
    915  UNIQUE KEY `uniq_name` (`name`) 
    10 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
     16) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
    1117 
    1218INSERT INTO `roles` (`id`, `name`, `description`) VALUES(1, 'login', 'Login privileges, granted after account confirmation'); 
    1319INSERT INTO `roles` (`id`, `name`, `description`) VALUES(2, 'admin', 'Administrative user, has access to everything.'); 
     20 
     21CREATE TABLE IF NOT EXISTS `roles_users` ( 
     22  `user_id` int(10) unsigned NOT NULL, 
     23  `role_id` int(10) unsigned NOT NULL, 
     24  PRIMARY KEY  (`user_id`,`role_id`), 
     25  KEY `fk_role_id` (`role_id`) 
     26) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
    1427 
    1528CREATE TABLE IF NOT EXISTS `users` ( 
     
    2336  UNIQUE KEY `uniq_username` (`username`), 
    2437  UNIQUE KEY `uniq_email` (`email`) 
    25 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
    26  
    27 CREATE TABLE IF NOT EXISTS `users_roles` ( 
    28   `user_id` int(10) unsigned NOT NULL, 
    29   `role_id` int(10) unsigned NOT NULL, 
    30   PRIMARY KEY  (`user_id`,`role_id`) 
    31 ) ENGINE=MyISAM DEFAULT CHARSET=utf8; 
     38) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
    3239 
    3340CREATE TABLE IF NOT EXISTS `user_tokens` ( 
     
    3946  `expires` int(10) unsigned NOT NULL, 
    4047  PRIMARY KEY  (`id`), 
    41   UNIQUE KEY `uniq_token` (`token`) 
    42 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8; 
    43 </pre> 
     48  UNIQUE KEY `uniq_token` (`token`), 
     49  KEY `fk_user_id` (`user_id`) 
     50) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
    4451 
    45 <p>After the tables have been installed, <?php echo html::anchor('auth_demo/create', 'create a user') ?>.</p> 
     52ALTER TABLE `roles_users` 
     53  ADD CONSTRAINT `roles_users_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE, 
     54  ADD CONSTRAINT `roles_users_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE; 
     55 
     56ALTER TABLE `user_tokens` 
     57  ADD CONSTRAINT `user_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE; 
     58EOF 
     59, 'style="width:90%;height:30em;padding:0.5em"') ?> 
     60 
     61</div>