double authentication

Hello!

Any ideas on how to approach this workflow on yii?

Auth no1: (autologin)

  • A guest access index.php

  • if $_SERVER[‘LOGON_USER’] exists in a db Table then no login required and show standard links $apps[]

  • result: user1 is authenticated

Auth no2:

  • but some of the links do require login {user/pass}

  • when user1 try to access a restricted link then login form appears

Any ideas please? I’m moving in circle on this…

kind regards,

soter

you can do this using access control and define its rules in your controllers.




public function accessRules()


	{


		return array(


			array('allow',  // allow all users to perform 'index' and 'view' actions


				'actions'=>array('index','read'),


				'users'=>array('*'),


			),


			array('allow', // allow authenticated user to perform 'create' and 'update' actions


				'actions'=>array('create','update','add','admin','delete'),


				'users'=>Yii::app()->getModule('user')->getAdmins(),


			),




			array('deny',  // deny all users


				'users'=>array('*'),


			),


		);


	}



[color="#006400"]/* moved to general Yii 1.1 discussion */[/color]

Than you for your answer :)

now let’s expand a little:

Auth no1: (autologin)

  • A guest access index.php

  • if $_SERVER[‘LOGON_USER’] exists in a db Table then no login required and show standard links $apps[]

  • result: user1 is authenticated and see only the links defined to this user in database

Auth no2:

  • but some of the links do require login {user/pass}

  • when user1 try to access a restricted link then login form appears

What do you say?

I would create a widget to create this menu




//view code

if(!Yii::app()->user->isGuest){

 $this->widget('UserMenu');

}

//UserMenu widget

Yii::import('zii.widgets.CPortlet');

class UserMenu extends CPortlet{

  public $title='User menu';

  function renderContent(){

   $models=UserLink::model()->activeUser()->findAll();

   $links=array();

   foreach($models as $model){

	$links[]=array('label'=>$model->label,'url'=>$model->url)

   }

   $this->widget('zii.widgets.CMenu',array(

	'items'=>$links

   ));

  }

}

//UserLink model

class UserLink extends CActiveRecord{

 //...

 function scopes(){

 return array(

  'activeUser'=>array(

   'condition'=>'user_id=:userID',

   'params'=>array('userID'=>Yii::app()->user->id),

   )

  );

 }

}



That would do it

Also, an access rule could be something like this




array('allow', 

 'actions'=>array('index','read'),

 'expression'=>'isset($_SERVER["LOGON_USER"])',

),




wow, almost enlightened :) than you very much!