Yii Framework Forum: Using The Same Model For Site Login And For Admin Login - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using The Same Model For Site Login And For Admin Login Rate Topic: -----

#1 User is offline   moldnix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-January 14

Posted 20 January 2014 - 10:13 AM

Hi, i use the same model to login the users and to login in admin module.
For admin i have a row where 1 = admin 0 = user.
how can i restrict users to login in the admin module where the admin row in users table is 0?
0

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,382
  • Joined: 21-February 11
  • Location:Greece

Posted 20 January 2014 - 10:23 AM

Hi

How check the access for each controller/action ?
please give us more details...
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   moldnix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-January 14

Posted 20 January 2014 - 10:38 AM

This are acces rules for default controller in admin module

public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index'),
				'users'=>array('@'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

0

#4 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,703
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 20 January 2014 - 10:42 AM

Like this for example:

public function accessRules() {
    return array(
        array('allow',
            'expression' => '$user->getState("isAdmin") == 1',
        ),
        array('deny',
            'users' => array('*'),
        ),
    );
}


More on that here: http://www.yiiframew...pression-detail
God is real unless declared as integer
0

#5 User is offline   moldnix 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-January 14

Posted 20 January 2014 - 10:57 AM

View PostORey, on 20 January 2014 - 10:42 AM, said:

Like this for example:

public function accessRules() {
    return array(
        array('allow',
            'expression' => '$user->getState("isAdmin") == 1',
        ),
        array('deny',
            'users' => array('*'),
        ),
    );
}


More on that here: http://www.yiiframew...pression-detail


Thank you
For me worked so:
public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index'),
				'expression' => 'Yii::app()->user->isAdmin()',
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}

0

#6 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,382
  • Joined: 21-February 11
  • Location:Greece

Posted 20 January 2014 - 11:23 AM

View Postmoldnix, on 20 January 2014 - 10:57 AM, said:

Thank you
For me worked so:
public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index'),
				'expression' => 'Yii::app()->user->isAdmin()',
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}




Also If you use RBAC (see http://www.yiiframew...28/simple-rbac/)
you could just use
 'roles'=>array('admin', 'or_whatever_role_you_want'),

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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