Finora tra tutti i moduli che ho visto, mi sembra uno di quelli fatti meglio.
Prima avevo provato srbac ma direi che non c'è proprio confronto
e quindi ne consiglio sicuramente la sua installazione.
La guida in inglese che meglio mi ha aiutato è stata questa qui:
http://yii-rights.go...s-doc-1.2.0.pdf
1) Per prima cosa bisogna creare la tabella per la gestione delle utenze
CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(128) COLLATE utf8_bin NOT NULL, `password` varchar(128) COLLATE utf8_bin NOT NULL, `remember` tinyint(1) DEFAULT NULL, `email` varchar(128) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4 ; INSERT INTO `user` VALUES(1, 'khurram', 'password', NULL, 'khurram_619@msn.com'); INSERT INTO `user` VALUES(2, 'demo', 'demo', NULL, 'demo@demo.it');
2) poi tramite gii, creare la classe User associata alla tabella del db
3) scaricare il modulo rigths da qui:
http://code.google.c.../downloads/list
4) scompattare il tutto nella cartella modules (che potrebbe essere da creare)
in modo che venga fuori così protected\modules\rights
5) modificare la configurazione dell'applicazione /protected/config/main.php così:
'import'=>array( ...... 'application.modules.rights.*', 'application.modules.rights.components.*', // Correct paths if necessary. ), ...... 'components'=>array( ...... 'user'=>array( 'class'=>'RWebUser', // Allows super users access implicitly. ...... ), 'authManager'=>array( 'class'=>'RDbAuthManager', // Provides support authorization item sorting. ...... ), ...... ), 'modules'=>array( 'rights'=>array( 'install'=>true, // Enables the installer. ),),
Per eventuali confronti riporto la mia unit main.php completa:
<?php
error_reporting(E_ALL ^ E_NOTICE);
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Esperimenti del Janka',
'language'=>'it',//W l'Italia
'sourceLanguage'=>'it_IT',//W l'italiano
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
//Per usare il modulo RIGHTS
'application.modules.rights.*', // Le paths contenenti rights
'application.modules.rights.components.*', //I:\prova\demo\protected\modules\rights
//Vedi anche la guida
//http://yii-rights.googlecode.com/files/yii-rights-doc-1.2.0.pdf
),
'modules'=>array(
// togliere il commento sulla seguente riga per abilitare i Gii tool
//Una volta abilitato, puoi accedere ai gii tool da questo url:
//http://localhost/prova/demo/index.php/gii/
//Se non lo abiliti in questo modo:
//http://localhost/prova/demo/index.php?r=gii
//Se non sai come si usa questo tool, guarda questi video:
//http://www.yiiframework.com/screencasts/
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pino',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
// 'ipFilters'=>array('127.0.0.1','::1'),
//Imposto che possano accedere solo le macchine della rete 10.1.0.*
'ipFilters'=>array('10.1.0.*','::1'),
),
/*
* Inizio gestione del modulo rights per la gestione dell'autenticazione
* per i dettagli leggere la guida in inglese:
* http://yii-rights.googlecode.com/files/yii-rights-doc-1.2.0.pdf
* per usare questo modulo
* ho hanche ritoccato le sezioni "import" e aggiunto
* authManager e user in components
*/
//Voglio usare il modulo rigths
'rights'=>array(
'install'=>true, // Abilita l'installer.
//Quelli che seguono sono i parametri di default, potrei anche saltarli
/*
'userIdColumn'=>'id', // Il nome della colonna user id nel database.
'userNameColumn'=>'username', // Il nome della colonna name nel database.
'superuserName'=>'Admin', // Name of the role with super user privileges.
'authenticatedName'=>'Authenticated', // Name of the authenticated user role.
'enableBizRule'=>true, // Whether to enable authorization item business rules.
'enableBizRuleData'=>false, // Per abilitare data for business rules.
'displayDescription'=>true, // Per usare la descrizione dell'oggetto al posto del nome.
'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages.
'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages.
'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested.
'layout'=>'rights.views.layouts.main', // Layout to use for displaying Rights.
'appLayout'=>'application.views.layouts.main', // Application layout.
'cssFile'=>'rights.css', // Style sheet file to use for Rights.
'debug'=>false, // Per abilitare la modalità di debug.
*/
),
/*
* Fine gestione modulo rights
*/
),
// application components
'components'=>array(
'user'=>array(
'class' => 'RWebUser', // Consento l'accesso implicitamente ai super users.
'allowAutoLogin'=>true, // abilito l' autenticazione basata su cookie
),
//dico a Yii che voglio gestire l'autenticazione utenti tramite db
'authManager'=>array(
'class'=>'RDbAuthManager',
),
// Abilito la gestione degli URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
// per usare il MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=yii_tour',
'emulatePrepare' => true,
'username' => 'la tua user',
'password' => 'la tua psw',
'charset' => 'utf8',
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'pino@gmail.com',
),
);
6) Avendo abilitato l'installazione automatica delle tabelle necessarie con
'rights'=>array(
'install'=>true,
)
posso a questo punto testare da web il modulo
..../index.php/rights/
e se tutto ha funzionato dovrebbe aver creato e popolato le nuove tabelle AuthAssignment, AuthItem, AuthItemChild
In questa discussione puoi trovare ulteriori utili suggerimenti per risolvere eventuali problemi con l'installazione di rights
7) una volta fatta l'installazione, ricordarsi di disabilitarla andando a modificare nel main.php
'rights'=>array( 'install'=>false, // Disabilita l'installer. ),
9) Comprendere come gestire le autorizzazioni
Potrebbe esserti d'aiuto anche questa piccola applicazione didattica per approfondire la costruzione di un form che implementa login e registrazione

Help




Non preoccuparti, è dentro il monitor!











