Yii Framework Forum: Problem with accessRules - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Problem with accessRules Rate Topic: -----

#1 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 28 September 2011 - 09:19 AM

Hi friends,


I have some problem with accessRules.
My intention is to check the login for relevant pages.

I wrote accessRules in one controller, say AccountsController as:


public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }
    
    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('index', 'forgotpassword', 'changepassword', 'register',
                    'captcha', 'login', 'confirmindividualuser',
                    'plans', 'confirmmerge', 'accountmerged', 'plandetails', 'individualaccount', 'registrationsuccess',
                    'forgotpasswordsuccess', 'individualprofile', 'invalid', 'company', 'companyprofile', 'logout'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('companyprofilesuccess','changepasswordsuccess'),
                '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('*'),
            ),
        );
    }




Once login I have to redirect to another method which is in SurveyController.
So I wrote as :

    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * 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(),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('index', 'main', 'contacts', 'commercial', 'documents',
                    'form', 'savequestions', 'formaddsection', 'formaddquestion',
                    'formeditquestion', 'formdeletesection', 'formdeletequestion',
                    'picksection', 'pickquestion', 'preview', 'send', 'createlink'),
                '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('*'),
            ),
        );
    }



Also I added the loginUrl in config file(main.php) as

'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
            'loginUrl'=>array('accounts/login'),
        ),



But My problem is while I type the methods in SurveyController, the browser still showing the page without checking the user login. Please give me a solution ...


Thanks in advance...
Jaison
0

#2 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 28 September 2011 - 10:27 AM

Maybe this is because you have a first rule with empty 'actions':
      array('allow', // allow all users to perform 'index' and 'view' actions
           'actions' => array(),
           'users' => array('*'),
      ),

see http://www.yiiframew...#actions-detail - if no actions specified then the rule applies to all actions.
0

#3 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 29 September 2011 - 12:23 AM

View Postseb, on 28 September 2011 - 10:27 AM, said:

Maybe this is because you have a first rule with empty 'actions':
      array('allow', // allow all users to perform 'index' and 'view' actions
           'actions' => array(),
           'users' => array('*'),
      ),

see http://www.yiiframew...#actions-detail - if no actions specified then the rule applies to all actions.



Thanks friends but I am still having problem.
Now I wrote script as:

    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('invalid'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('index','main','contacts','commercial','documents','form','savequestions','formaddsection','formaddquestion','formeditquestion','formdeletesection','formdeletequestion','picksection','pickquestion','preview','send','createlink'),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('invalid2'),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }




But I got error like "

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept
cookies.

"



I remove cookies also. Still getting similar problem. Please help me.


Thanks in advance..
0

#4 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 29 September 2011 - 08:56 AM

Maybe the page you redirected to when not authenticated is also protected by access rule?

Most fast way to find out what is going on is to use debugger - you can set breakpoint in the index.php and step into yii code to find where redirect is performed and to what route. I usually do this when I have problems with url rules or access rules configuration when I can not understand why it works not right.
0

#5 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 29 September 2011 - 09:49 AM

View Postseb, on 29 September 2011 - 08:56 AM, said:

Maybe the page you redirected to when not authenticated is also protected by access rule?

Most fast way to find out what is going on is to use debugger - you can set breakpoint in the index.php and step into yii code to find where redirect is performed and to what route. I usually do this when I have problems with url rules or access rules configuration when I can not understand why it works not right.



Thanks, but I am new in such technique. Can you tell me how to configure xdebug in xampp without affecting the server. I tried googling but I get confused. Can you please help me.
It could save my time. Actually I am stuck in front of it :(.

Thanks in advance..
Jaison
0

#6 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 29 September 2011 - 12:49 PM

I think XAMPP should already include xdebug, so it can just work.
In short you need to:
- install xdebug php extension
- configure xdebug extension
- setup some IDE (eclipse, netbeans, almost any IDE which supports php development also supports debugging with xdebug)
Try to search this forum and yii wiki for more details, for example: http://www.yiiframew...d-yii-projects/ and http://www.yiiframew...sing-netbeans/.
If you plan to work with yii (or any other framework or even without framework) it is worth to invest some time in learning how to debug php code. This is also the best way to learn framework in my opinion.
0

#7 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 03 October 2011 - 01:34 AM

View Postseb, on 29 September 2011 - 12:49 PM, said:

I think XAMPP should already include xdebug, so it can just work.
In short you need to:
- install xdebug php extension
- configure xdebug extension
- setup some IDE (eclipse, netbeans, almost any IDE which supports php development also supports debugging with xdebug)
Try to search this forum and yii wiki for more details, for example: http://www.yiiframew...d-yii-projects/ and http://www.yiiframew...sing-netbeans/.
If you plan to work with yii (or any other framework or even without framework) it is worth to invest some time in learning how to debug php code. This is also the best way to learn framework in my opinion.


Thanks friend,
I cud setup xdebug but still my issue exists..I cudn't find out the issue using the xdebug.. Any solution ? Please help me
0

#8 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 03 October 2011 - 08:52 AM

Can you give more info?
How your main.php config looks like and what is now in your controllers.
Also what did you found with xdebug? Are you able to step code line by line and find where you redirected?
0

#9 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 03 October 2011 - 11:18 PM

View Postseb, on 03 October 2011 - 08:52 AM, said:

Can you give more info?
How your main.php config looks like and what is now in your controllers.
Also what did you found with xdebug? Are you able to step code line by line and find where you redirected?


main.php(config file)


<?php

// 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' => 'Web App',
    // preloading 'log' component
    'preload' => array('log'),
    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
        'application.controllers.*'
    ),
    'modules' => array(
        // uncomment the following to enable the Gii tool		
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => 'yiid#m0',
            // 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,
            'loginUrl'=>array('accounts/login'),
        ),        
        //uncomment the following to enable URLs in path-format		
        'urlManager' => array(
            'urlFormat' => 'path',
            'showScriptName' => false,
            'rules' => array('' => 'accounts/login'),
        ),
        // uncomment the following to use a MySQL database
        'db' => array(
            'connectionString' => 'mysql:host=localhost;dbname=sample',
            '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',
              ),
             */
            ),
        ),
        'session' => array(
            'class' => 'CDbHttpSession',
            'connectionID' => 'db',
        ),
        'authManager' => array(
            'class' => 'CDbAuthManager',
            'connectionID' => 'db',
        ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    ),
);




My AccountController accessRules()

    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }
    /**
     * 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', 'forgotpassword', 'changepassword', 'register',
                    'captcha', 'login', 'confirmindividualuser',
                    'plans', 'confirmmerge', 'accountmerged', 'plandetails', 'individualaccount', 'registrationsuccess',
                    'forgotpasswordsuccess', 'individualprofile', 'invalid', 'company', 'companyprofile', 'logout'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('companyprofilesuccess','changepasswordsuccess'),
                '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('*'),
            ),
        );
    }



My SurveyController accessRules


    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }
    /**
     * 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('invalid'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('index','main','contacts','commercial','documents','form','savequestions','formaddsection','formaddquestion','formeditquestion','formdeletesection','formdeletequestion','picksection','pickquestion','preview','send','createlink'),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('invalid2'),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }


0

#10 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 04 October 2011 - 09:25 AM

I think this is may be due to url rule:
'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'rules' => array('' => 'accounts/login'),
),

If you want to set default controller and action then you can use appropriate web application property:
'defaultController' => 'accounts',

and in your controller you can set a default action
class AccountsController extends CController
{

  public $defaultAction = 'login';

...
}

0

#11 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 06 October 2011 - 01:31 AM

View Postseb, on 04 October 2011 - 09:25 AM, said:

I think this is may be due to url rule:
'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'rules' => array('' => 'accounts/login'),
),

If you want to set default controller and action then you can use appropriate web application property:
'defaultController' => 'accounts',

and in your controller you can set a default action
class AccountsController extends CController
{

  public $defaultAction = 'login';

...
}





Sorry Friend,

Still the same problem... Please help me .. I am struck in front of it.. :(
0

#12 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 06 October 2011 - 01:44 AM

I have no other idea now, but I already started with help... So if you make a simple mini application where this problem is reproduced I can look at it locally and find what causes the problem. You can generate separate app or reduce your existing app or pack the whole existing app into archive and attach here.
0

#13 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 10 October 2011 - 11:04 AM

Did you solved your problem?
0

#14 User is offline   Jaison Justus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 25-August 11
  • Location:Trivandrum

Posted 14 October 2011 - 04:18 AM

View Postseb, on 10 October 2011 - 11:04 AM, said:

Did you solved your problem?


Dear Friend,

No I couldn't solve it... I put it in a side burner.. :) to finish the remaining work...
But have to solve it.. Any idea or solution for this?

Thanks,
Jaison
0

#15 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 17 October 2011 - 09:16 AM

See my comment above - if you can provide a simple application with this problem I can check and solve it. I am almost sure it is something minor and can be easily solved.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users