yii user and rights- admin can not access any page - yii

Fatal error: Call to undefined method Rights::t()
Getting this error when ever i want to go in any controller or in any controller's action. I am using yii user and rights. for instance when i type localhost/business/address/create i get the above error.
Yii user is working fine, even rights too. But i cannot access any controller.
'bootstrap',
'basePath'=>dirname(FILE).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
// preloading 'log' component
'preload'=>array('log'),
'aliases' => array(
'bootstrap' => 'ext.bootstrap' ),
// autoloading model and component classes
'import'=>array(
//addedd these lines
'application.modules.user.models.*',
'application.modules.user.components.*',
'application.modules.rights.*',
'application.modules.rights.components.*',
'application.models.*',
'application.components.*',
'bootstrap.behaviors.*',
'bootstrap.helpers.*',
'bootstrap.widgets.*'
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'centangle',
'generatorPaths' => array( 'bootstrap.gii', ),
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
'user'=>array(
'tableUsers' => 'user',
'tableProfiles' => 'profiles',
'tableProfileFields' => 'profiles_fields',
# encrypting method (php hash function)
'hash' => 'md5',
# send activation email
'sendActivationMail' => true,
# allow access for non-activated users
'loginNotActiv' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
# automatically login from registration
'autoLogin' => true,
# registration path
'registrationUrl' => array('/user/registration'),
# recovery password path
'recoveryUrl' => array('/user/recovery'),
# login form path
'loginUrl' => array('/user/login'),
# page after login
'returnUrl' => array('/user/profile'),
# page after logout
'returnLogoutUrl' => array('/user/login'),
),
'rights'=>array(
'install'=>true,
'superuserName'=>'admin', // Name of the role with super user privileges.
'authenticatedName'=>'Authenticated', // Name of the authenticated user role.
'userIdColumn'=>'id', // Name of the user id column in the database.
'userNameColumn'=>'username', // Name of the user name column in the database.
'enableBizRule'=>true, // Whether to enable authorization item business rules.
'enableBizRuleData'=>true, // Whether to enable data for business rules.
'displayDescription'=>true, // Whether to use item description instead of name.
'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.
'install'=>false, // Whether to enable installer.
'debug'=>false,
),
),
// application components
'components'=>array(
'user'=>array(
'class'=>'WebUser',
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl'=>array('/user/login'),
),
'authManager'=>array(
'class'=>'RDbAuthManager',
'connectionID'=>'db',
'itemTable'=>'authitem',
'itemChildTable'=>'authitemchild',
'assignmentTable'=>'authassignment',
'rightsTable'=>'rights',
'defaultRoles'=>array('Authenticated', 'Guest'),
),
'bootstrap' => array(
'class' => 'bootstrap.components.BsApi', ),
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'user/registration/<id:\w+>' => 'user/registration',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
/*'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=copy',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'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'=>'webmaster#example.com',
),
);
and this is my controller business
class BusinessController extends RController
{
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
'rights',
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* #return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('#'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
* #param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Business;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Business']))
{
$model->attributes=$_POST['Business'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* #param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Business']))
{
$model->attributes=$_POST['Business'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* #param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Business');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Business('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Business']))
$model->attributes=$_GET['Business'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* #param integer $id the ID of the model to be loaded
* #return Business the loaded model
* #throws CHttpException
*/
public function loadModel($id)
{
$model=Business::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* #param Business $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='business-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}

it is because of this mistake.the problem lies in the writing of the code, make sure you must write your code in config.main like this
'import' => array(
'application.models.*',
'application.components.*',
'bootstrap.behaviors.*',
'bootstrap.helpers.*',
'bootstrap.widgets.*',
//add this code after the above code and thats it, a small stupid mistake may cost you 3 days of hard debugging.
'application.modules.user.models.*',
'application.modules.user.components.*',
'application.modules.rights.*',
'application.modules.rights.components.*'
),

Related

form goes blank on use of TbExtendedGridView

I am new to yii1. In my project ,I have used TblExtendedGridView to display data in the table .The form shows the data in my local computer.But when the project is uloaded in server,the file is blank and doesnot show any error.
What is the problem?
'<?php
$uniqid=md5(uniqid());
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'marketing-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'type' => 'striped bordered',
'type' => 'striped bordered condensed',
'columns'=>array(
array(
'header'=>'#',
'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
array(
'name'=>'client_id',
'header'=>'Company',
'value'=>'$data->clientName->client_name',
'htmlOptions' => array('style'=>'width:200px'),
),
array(
'name'=>'client_contact_id',
'header'=>'Contacted',
'value'=>'$data->contactPerson->contact_name',
'htmlOptions' => array('style'=>'width:180px'),
),
array(
'name'=>'visited_date',
'header'=>'Visit Date',
'htmlOptions' => array('style'=>'width:100px'),
),
array(
'name'=>'possibility',
'header'=>'Probability',
'htmlOptions' => array('style'=>'width:100px'),
),
'remarks',
array(
'name'=>'next_visited_date',
'header'=>'Next Contact Date',
'htmlOptions' => array('style'=>'width:100px'),
),
array(
'name'=>'follow_up_by',
'header'=>'Follow Up By',
'value'=>'$data->followPerson->user_name',
'htmlOptions' => array('style'=>'width:180px'),
),
),
),
),
)); ?>'
'My controller is:
<?php
class MarketingController extends Controller
{
public $layout='//layouts/column1';
public function actionIndex()
{
$this->actionAdmin();
}
// Uncomment the following methods and override them if needed
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','DynamicContact'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('admin','delete','create','update','DynamicContact'),
'users'=>array('#'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete','DynamicContact'),
'users'=>array('admin','#'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='marketing-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
public function actionView($id)
{
EQuickDlgs::render('view',array('model'=>$this->loadModel($id)));
}
public function actionAdmin()
{
$model=new Marketing('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Marketing']))
$model->attributes=$_GET['Marketing'];
$this->render('admin',array(
'model'=>$model,
));
}
public function actionCreate()
{
$model=new Marketing;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Marketing']))
{
$model->attributes=$_POST['Marketing'];
//print_r($_POST['User']);
//die;
if($model->save())
{
EQuickDlgs::checkDialogJsScript();
$this->redirect(array('marketing/admin','id'=>$model->marketing_id));
}
}
EQuickDlgs::render('create',array(
'model'=>$model,
));
}
public function loadModel($id)
{
$model=Marketing::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Marketing']))
{
$model->attributes=$_POST['Marketing'];
if($model->save())
{
//$this->redirect(array('view','id'=>$model->user_id));
EQuickDlgs::checkDialogJsScript();
$this->redirect(array('marketing/admin','id'=>$model->marketing_id));
}
}
EQuickDlgs::render('update',array(
'model'=>$model,
));
}
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
}'
'And Model is :
<?php
class Marketing extends PMActiveRecord
{
/**
* #return string the associated database table name
*/
public function tableName()
{
return 'pm_mar_marketing';
}
public function rules()
{
return array(
array('client_id, client_contact_id, follow_up_by, visited_date, visit_type, next_visited_date, possibility, remarks', 'required'),
array('client_id, client_contact_id, follow_up_by, visit_type, crtd_by, updt_by, updt_cnt', 'numerical', 'integerOnly'=>true),
array('possibility', 'length', 'max'=>20),
// The following rule is used by search().
// #todo Please remove those attributes that should not be searched.
array('marketing_id, client_id, client_contact_id, follow_up_by, visited_date, visit_type, next_visited_date, possibility, remarks', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'clientName' => array(self::BELONGS_TO, 'Client', 'client_id'),
'contactPerson' => array(self::BELONGS_TO, 'ClientContact', 'client_contact_id'),
'followPerson' => array(self::BELONGS_TO, 'User', 'follow_up_by'),
'visitType' => array(self::BELONGS_TO, 'CodeValue', 'visit_type')
);
}
/**
* #return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'marketing_id' => 'Marketing',
'client_id' => 'Client',
// 'client_id'=> 'Client',
'client_contact_id' => 'Contact Person',
//'client_contact_id' => 'Contact Person',
'follow_up_by' => 'Follow Up By',
'visited_date' => 'Visited Date',
'visitType.code_lbl' => 'Visit Type',
'next_visited_date' => 'Next Contact Date',
'possibility' => 'Probability',
'remarks' => 'Remarks',
'crtd_by' => 'Crtd By',
'crtd_dt' => 'Crtd Dt',
'updt_by' => 'Updt By',
'updt_dt' => 'Updt Dt',
'updt_cnt' => 'Updt Cnt',
);
}
public function search()
{
// #todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('clientName','contactPerson','followPerson');
$criteria->compare('marketing_id',$this->marketing_id);
$criteria->compare('clientName.client_name',$this->client_id,true);
$criteria->compare('contactPerson.contact_name',$this->client_contact_id,true);
$criteria->compare('followPerson.user_name',$this->follow_up_by,true);
$criteria->compare('visited_date',$this->visited_date,true);
//$criteria->compare('visit_type',$this->visit_type);
$criteria->compare('next_visited_date',$this->next_visited_date,true);
$criteria->compare('possibility',$this->possibility,true);
$criteria->compare('remarks',$this->remarks,true);
$criteria->compare('crtd_by',$this->crtd_by);
$criteria->compare('crtd_dt',$this->crtd_dt,true);
$criteria->compare('updt_by',$this->updt_by);
$criteria->compare('updt_dt',$this->updt_dt,true);
$criteria->compare('updt_cnt',$this->updt_cnt);
//$criteria -> join = 'INNER JOIN pm_marketing_user followPerson on t.follow_up_by= followPerson.user_id';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
'
If This happend only whit this view check for the lowercase/uppercase of the class code file (Marketing.php i guess)
If your development enviroment is windows and your produdction enviroment is Unix like, can happen yuo have marketing.php in your model and you referer to Marketing.php or to the contrary this work in windows/dos because in case insentisitve but not in Unix like O.S.

ZF2 / doctrine ORM authentication different Entity

in my application (ZF2 / ORM) i have 3 Entities (with Single Table inheritance)
User
Owner extends User
Agent extends User
i want to make one single Authentication (Login) for the 3 Entity using
doctrine.authenticationservice.orm_default
module.config.php
//other doctrine config
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Application\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
'credential_callable' => function(User $user, $passwordGiven) {
return $user->getPassword() == md5($passwordGiven);
},
),
),
and the process of login
//LoginController.php
// ..data validation
$this->authService = $this->getServiceLocator()->get('doctrine.authenticationservice.orm_default');
$AuthAdapter = $this->authService->getAdapter();
$AuthAdapter->setIdentity($this->request->getPost('email'));
$AuthAdapter->setCredential(md5($this->request->getPost('password')));
$result = $this->authService->authenticate();
if($result->isValid()){
$identity = $result->getIdentity();
//continue
}
how can i do this process without caring about object type,
when i try to login with email of an Agent, i get this error
Catchable fatal error: Argument 1 passed to Application\Module::{closure}() must be an instance of User, instance of Application\Entity\Owner given
The error you mention is due to the type hint on:
function(User $user) {
Which leads me to believe that you have a missing namespace declaration in your config file; in which case you can either add it or use the FQCN.
function(\Application\Entity\User $user) {
Nevertheless, I don't think it's actually the problem. You can only define one 'identity_class' with doctrine authentication (which the adapter will use to load the entity from the entity manager). If you have multiple entity classes there is no way to have each of these tested with one adapter.
However, the configuration is really just creating a new authentication adapter, specifically DoctrineModule\Authentication\Adapter\ObjectRepository. One solution would be to create multiple ObjectRepository adapters, each with the correct configuration for the different entities and then loop through each of them while calling authenticate() on the Zend\Authentication\AuthenticationService.
For example :
public function methodUsedToAutheticate($username, $password)
{
// Assume we have an array of configured adapters in an array
foreach($adapters as $adapter) {
$adapter->setIdentity($username);
$adapter->setCredential($password);
// Authenticate using the new adapter
$result = $authService->authenticate($adapter);
if ($result->isValid()) {
// auth success
break;
}
}
return $result; // auth failed
}
As previously mentioned is the doctrine config will not allow for more than one adapter, so you would need to create them manually and remove your current configuration.
Another example
public function getServiceConfig()
{
return [
'factories' => [
'MyServiceThatDoesTheAuthetication' => function($sm) {
$service = new MyServiceThatDoesTheAuthetication();
// Assume some kind of api to add multiple adapters
$service->addAuthAdapter($sm->get('AuthAdapterUser'));
$service->addAuthAdapter($sm->get('AuthAdapterOwner'));
$service->addAuthAdapter($sm->get('AuthAdapterAgent'));
return $service;
},
'AuthAdapterAgent' => function($sm) {
return new DoctrineModule\Authentication\Adapter\ObjectRepository(array(
'object_manager' => $sm->get('ObjectManager'),
'identity_class' => 'Application\Entity\Agent',
'identity_property' => 'email',
'credential_property' => 'password'
));
},
'AuthAdapterOwner' => function($sm) {
return new DoctrineModule\Authentication\Adapter\ObjectRepository(array(
'object_manager' => $sm->get('ObjectManager'),
'identity_class' => 'Application\Entity\Owner',
'identity_property' => 'email',
'credential_property' => 'password'
));
},
// etc...
],
];
}
Hopefully this gives you some ideas as to what is required.
Lastly, if you would consider other modules, ZfcUser already has a 'chainable adapter' which actually does the above (but uses the event manager) so It might be worth taking a look at even if you don't use it.

YII LDAP connection for user authentication

I am new to yii frame work I am trying to create an ldap configuration for user authentication
The following steps which I taken to create but it throws eerro as below
include(Controller.php) [function.include]: failed to open stream: No such file or directory
C:\xampp\htdocs\yiif\framework\YiiBase.php(418)
steps:
1. I have included the following ldaprecord/
extension in C:\xampp\htdocs\seed2\protected\extensions\ldaprecord
2. I have included the following code in config/main.php
`'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxxx',
'port' => 389,
//'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass#123',
'base_dn' => 'dc=rsales,dc=demo,dc=com'),);
'params'=>array(
// this is used in contact page
'adminEmail'=>'sundarapandian#rsalesarm.com',
),
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxx',
'port' => 389,
//'bind_rdn' => 'cn=xxxx xxxx,cn=Users,dc=xxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass#123',
'base_dn' => 'dc=xxxxx,dc=demo,dc=com'),
);`
included this line in the index.php
$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php';
and I have changed the useridentity authentication function as
`
public function authenticate()
{
$username=$this->username;
$password=$this->password;
$dname= 'xxxxxxx';
$options['host']='ldap://192.168.x.xxx';
$options['port']=389;
$ldap_username = "CN=".$username.",CN=Users,DC=xxxx,DC=demo,DC=com";
$options = Yii::app()->params['ldap'];
print_r($options);
$connection = ldap_connect($options['host'], $options['port']);
//print_r($connection);
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
if($connection)
{
echo "success";
//exit;
try
{
//echo $connection.$ldap_username.$this->password;
//print_r(ldap_bind($connection,$dname."\\". $ldap_username, $password));
//exit;
#$bind = ldap_bind($connection,$dname."\\". $ldap_username, $password);
print_r(#$bind);
if(#$bind)
{
echo "successfully logedin";
}
}
catch (Exception $e){
echo $e->getMessage();
}
if(!$bind) $this->errorCode = self::ERROR_PASSWORD_INVALID;
else $this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
};`
I am stucked here can any one help me hw to resolve this issue .please help me ,Thanks in advance..........
controller.php file was exists in the protected/components
even I check that it was included in the main .php
'import'=>array(
'application.models.*',
'application.components.*',
'ext.ldaprecord.*',
),
if I remove the following line the following error will shown
code:
$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php'
error:
Property "CWebApplication.ldap" is not defined.
yes I am using that extension only which u given link above([http://www.yiiframework.com/extension/ldaprecord/]),if u have any other extension please can u provide that link and what the steps need to be taken for that to implement .........thanks in advance..........
HIIIIII
I done mistake in the params now I have changed that as below , and I removed the
$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php';
it was not throwing any error .
I am including the my main.php full code below:
<?php
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'xxxxxx',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
//ldap config added code
'ext.ldaprecord.*',
),
'defaultController' => 'site/login',
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pass',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable 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>',
),
),*/
/*'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=xxxxx',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => '',
),
'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',
),
*/
),
),
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxx',
'port' => 389,
//'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass#123',
'base_dn' => 'dc=xxxxx,dc=demo,dc=com'),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'xxx#xxxx.com',
'ldap'=>array(
'class' => 'ext.ldaprecord.LdapComponent',
'server' => 'ldap://192.168.x.xxx',
'port' => 389,
//'bind_rdn' => 'cn=suren diran,cn=Users,dc=xxxxx,dc=demo,dc=com',
//'bind_pwd' => 'pass#123',
'base_dn' => 'dc=xxxx,dc=demo,dc=com'),
),
);
I am including my useridentity function below:
<?php
public function authenticate()
{
$options = Yii::app()->params['ldap'];
//print_r($options);
$connection = ldap_connect($options['host'], $options['port']);
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
if($connection)
{
// try
// {
//echo $options['domain']."\\".$this->username. $this->password;
//exit;
$ldap_username = "CN=".$this->username.",CN=xxxx,DC=xxxx,DC=demo,DC=com";
$ldap_password=$this->password;
echo $connection.$ldap_username.$ldap_password;
//$bind=ldap_bind($connection, $ldap_username, $ldap_password)
//exit;
//print_r(ldap_bind($connection,$ldap_username,$ldap_password));
$bind = #ldap_bind($connection,$ldap_username, $ldap_password);
print_r($bind);
//exit;
//#$bind = ldap_bind($connection,$ldap_username, $ldap_password);
// $abc=#$bind;
//print_r($abc);
//exit;
/*}
catch (Exception $e){
echo $e->getMessage();
}*/
if(!$bind) $this->errorCode = self::ERROR_PASSWORD_INVALID;
else $this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
But in the above one the ldap_bind is not working can u help on this ........
Please help me I how to overcome this .........thanks alot.....
I've just been reading this:
$config=dirname(__FILE__).'/protected/extensions/ldaprecord/CLdapRecord.php'
Why have you done that? I assume you're using this extension: It doesn't advise anywhere in thedocumentation to do so. This is pretty much emptying your application's config - including the import-stanza which is ultimately letting the include of the Controller.php fail.
Since you asked for another extension I would point you to this blog post. It's not an extension but is fairly detailed on how to set it up and looks like it will accomplish the same end goal for you.

Yii: Multimodelform Extension - How to create more than 1 member

I'm using Multimodelform extension to create multiple model in a single form.
This extension is working great but unfortunately i would like more than 1 member instead.
I have tried it without success at all.
My problem is I could not make more than 1 member by this extension.
Here's my code :
From Controller
public function actionCreate()
{
Yii::import('ext.multimodelform.MultiModelForm');
$model=new Endheader;
$member = new Enddetail;
$member2 = new Enddetailnq; <-- i just ant to this new member.
$validatedMembers = array();
//$validatedMembers2 = array();
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Endheader']))
{
$model->attributes=$_POST['Endheader'];
if(isset($_POST['sav'])){
if((MultiModelForm::validate($member, $validatedMembers, $deleteItems) && MultiModelForm::validate($member2, $validatedMembers, $deleteItems)) && $model->save())
{
$masterValues = array('HEH_ID'=>$model->HEH_ID);
if(MultiModelForm::save($member,$validatedMembers,$deleteItems,$masterValues) && MultiModelForm::save($member2,$validatedMembers,$deleteItems,$masterValues))
$msg2 = CHtml::link('View Details',array('view','id'=>$model->HEH_ID));
// $this->redirect(array('view','id'=>$model->HCO_ID));
Yii::app()->user->setFlash('success','You data have been saved successfully. '.$msg2);
$this->redirect(array('update','id'=>$model->HEH_ID));
}
}
}
$this->render('create',array(
'model'=>$model,'transport'=>$transport,
'member2'=>$member2,
'member'=>$member,
// 'validatedMembers2' => $validatedMembers2,
'validatedMembers' => $validatedMembers,
));
}
From View
$memberFormConfig = array(
'elements'=>array(
'HED_RPASS'=>array(
'type'=>'text',
'maxlength'=>11,
),
'HED_PCS'=>array(
'type'=>'text',
'maxlength'=>5,
),
));
$this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_member', //the unique widget id
'formConfig' => $memberFormConfig, //the form configuration array
'model' => $member, //instance of the form model
'tableView' => true,
//if submitted not empty from the controller,
//the form will be rendered with validation errors
'validatedItems' => $validatedMembers,
//'sortAttribute' => 'position',
//array of member instances loaded from db
'data' => $member->findAll('HEH_ID=:HEH_ID', array(':HEH_ID'=>$model->HEH_ID)),
));
$memberFormConfig2 = array(
'elements'=>array(
'HED_ARV_PCS'=>array(
'type'=>'text',
'maxlength'=>5,
),
'HED_ARV_VOL'=>array(
'type'=>'text',
'maxlength'=>10,
),
));
$this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_member2', //the unique widget id
'formConfig' => $memberFormConfig2, //the form configuration array
'model' => $member2, //instance of the form model
'tableView' => true,
//if submitted not empty from the controller,
//the form will be rendered with validation errors
'validatedItems' => $validatedMembers,
//'sortAttribute' => 'position',
//array of member instances loaded from db
'data' => $member->findAll('HEH_ID=:HEH_ID', array(':HEH_ID'=>$model->HEH_ID)),
));

Redirecting to login page to unauthorized user yii

access rules of pages controller:
public function accessRules()
{
$isadmin = User::loadUser(Yii::app()->user->id)->adminUser;
return array(
array('allow',
'actions'=>array('index','view','create','update'),
'expression'=>"{$isadmin}==1",
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
main config:
'user' => array( // Webuser for the admin area (admin)
'class' => 'WebUser',
'allowAutoLogin' => true,
'loginUrl' => array('/user/login'),
'stateKeyPrefix' => 'admin_',
),
Problem:
When I visit pages/create, it not redirected to user/login but throws the exception:
Error 404
The requested page does not exist.
How Can I redirect to login pages for unauthorized user?
You can use 'deniedCallback' to do this.
Method 1
'deniedCallback' => function() {Yii::app()->controller->redirect(array ('actionName'));},
//It will come As
array('allow',
'actions' => array('actionName1,actionName2,actionName3'),
'deniedCallback' => function() {Yii::app()->controller->redirect(array ('actionName'));},
'users' => array('#'),
),
Method 2:
You can also do the same by calling a function, see bellow code.
array('allow',
'deniedCallback' => array($this, 'goToLogin'),
'actions' => array('actionName1,actionName2,actionName3'),
'users' => array('#'),
),
Code for goToLogin method
public function goToLogin()
{
$this->redirect('/controller/actionName');
//For your program
//$this->redirect('/site/login');
}
Yii::app()->user->loginRequired();
add this funtion in every controller.
public function beforeAction($action) {
if (Yii::app()->user->isGuest && Yii::app()->controller->action->id != "login") {
Yii::app()->user->loginRequired();
}
//something code right here if user valid
return true;
}
site controller only needs Yii::app()->controller->action->id != "login" this condition. remove it for another controllers