Show
Ignore:
Timestamp:
08/30/2008 09:58:40 PM (3 months ago)
Author:
Shadowhand
Message:

Updated Auth:

  • Moved auth_demo controller to auth
  • Removed Forge usage in favor of Validation and form helper
  • Added auth/delete to delete user accounts; needs confirmation and admin checking
  • Made installation automatic using the default Database instance with queries
  • Added Model_User::validate() as a ORM validation example, for use with auth/create
  • Updated view layout and styles
Location:
trunk/modules/auth/views/auth
Files:
5 added
1 modified

Legend:

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

    r3267 r3403  
    11<div class="box"> 
     2 
     3<p class="intro">This demo will walk you through installing the Auth module using the ORM driver.</p> 
    24 
    35<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> 
    46 
    5 <p>After the tables have been installed, <?php echo html::anchor('auth_demo/create', 'create a user') ?>.</p> 
     7<p>After the tables have been installed, you will be able to <?php echo html::anchor('auth/create', 'create a user') ?>.</p> 
    68 
    79<p><em>This query is MySQL-specific, but should be easy to adapt to an database that supports foreign keys.</em></p> 
    810 
    9 <?php echo form::textarea('query', <<<EOF 
    10 CREATE TABLE IF NOT EXISTS `roles` ( 
    11   `id` int(11) unsigned NOT NULL auto_increment, 
    12   `name` varchar(32) NOT NULL, 
    13   `description` varchar(255) NOT NULL, 
    14   PRIMARY KEY  (`id`), 
    15   UNIQUE KEY `uniq_name` (`name`) 
    16 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
     11<?php echo form::open('auth') ?> 
    1712 
    18 INSERT INTO `roles` (`id`, `name`, `description`) VALUES(1, 'login', 'Login privileges, granted after account confirmation'); 
    19 INSERT INTO `roles` (`id`, `name`, `description`) VALUES(2, 'admin', 'Administrative user, has access to everything.'); 
     13<?php if (is_object($result) AND $result instanceof Exception): ?> 
     14<ul class="errors"> 
     15<li><?php echo $result->getMessage() ?></li> 
     16</ul> 
     17<?php endif ?> 
    2018 
    21 CREATE 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; 
     19<fieldset> 
     20<label><span>Installation SQL</span><?php echo form::textarea(array('name' => 'query', 'style' => 'height:30em'), $sql) ?></label> 
     21</fieldset> 
    2722 
    28 CREATE TABLE IF NOT EXISTS `users` ( 
    29   `id` int(11) unsigned NOT NULL auto_increment, 
    30   `email` varchar(127) NOT NULL, 
    31   `username` varchar(32) NOT NULL default '', 
    32   `password` char(50) NOT NULL, 
    33   `logins` int(10) unsigned NOT NULL default '0', 
    34   `last_login` int(10) unsigned, 
    35   PRIMARY KEY  (`id`), 
    36   UNIQUE KEY `uniq_username` (`username`), 
    37   UNIQUE KEY `uniq_email` (`email`) 
    38 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
     23<fieldset class="submit"><?php echo form::button(NULL, 'Run Query') ?></fieldset> 
    3924 
    40 CREATE TABLE IF NOT EXISTS `user_tokens` ( 
    41   `id` int(11) unsigned NOT NULL auto_increment, 
    42   `user_id` int(11) unsigned NOT NULL, 
    43   `user_agent` varchar(40) NOT NULL, 
    44   `token` varchar(32) NOT NULL, 
    45   `created` int(10) unsigned NOT NULL, 
    46   `expires` int(10) unsigned NOT NULL, 
    47   PRIMARY KEY  (`id`), 
    48   UNIQUE KEY `uniq_token` (`token`), 
    49   KEY `fk_user_id` (`user_id`) 
    50 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 
    51  
    52 ALTER 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  
    56 ALTER TABLE `user_tokens` 
    57   ADD CONSTRAINT `user_tokens_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE; 
    58 EOF 
    59 , 'style="width:90%;height:30em;padding:0.5em"') ?> 
     25<?php echo form::close() ?> 
    6026 
    6127</div>