Yii Authentication

Hii

I have created two user in my application 1)super User and 2)Authenticated

i want to create functionality like super user can direct login into authenticated account.

is there any way to do this by url?

view :

<?php echo CHtml::link(CHtml::tag(‘i’, array(‘class’=>‘glyphicon glyphicon-zoom-in icon-white’), ‘Login As’), array(“admin/loginas”,“user”=>$data->id),array(‘class’=>‘btn btn-success’)); ?>

controller :

private $_id;

const ERROR_EMAIL_INVALID=3;


const ERROR_STATUS_NOTACTIV=4;


const ERROR_STATUS_BAN=5;


public function actionLoginas(&#036;id)


{


	//&#036;model=new RightInfo('search');


	


	   &#036;model=User::model()-&gt;findByPk(&#036;id);


	


		&#036;user=User::model()-&gt;notsafe()-&gt;findByAttributes(array('username'=&gt;&#036;model-&gt;username));


	


	if(&#036;user===null)


		{


			&#036;this-&gt;errorCode=self::ERROR_USERNAME_INVALID;


		}


	 else if(Yii::app()-&gt;getModule('user')-&gt;&#036;model-&gt;password&#33;==&#036;user-&gt;password)


		&#036;this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;


	


		else if(&#036;user-&gt;parent_user&#33;=0 &amp;&amp; &#036;user-&gt;role_type==1)


	    {


		&#036;this-&gt;_id=&#036;user-&gt;parent_user;


		&#036;this-&gt;setState('thisuser', &#036;user-&gt;id);


		&#036;this-&gt;setState('role', &#036;user-&gt;role_type);


		&#036;this-&gt;username=&#036;user-&gt;username;


		&#036;this-&gt;errorCode=self::ERROR_NONE;


	}


	else {


		&#036;this-&gt;_id=&#036;user-&gt;id;


		&#036;this-&gt;username=&#036;user-&gt;username;


		&#036;this-&gt;setState('thisuser', &#036;user-&gt;id);


		&#036;this-&gt;setState('role', &#036;user-&gt;role_type);


		&#036;this-&gt;errorCode=self::ERROR_NONE;


	}


	return &#33;&#036;this-&gt;errorCode;


	//&#036;model-&gt;unsetAttributes();  // clear any default values


	


}

error 404 invalid request

Please Help…6397

testing.jpg

this might help you getting up to speed with admin and user logins

http://www.yiiframework.com/wiki/356/how-to-create-front-and-admin-side-login-form/

http://www.yiiframework.com/wiki/771/rbac-super-simple-with-admin-and-user/

thanks for your replay

but i am asking that is there any way to direct login with url passed data like username and password??

like

localhost/yii/project/index.php/user/admin/loginas?user=testuseruser&pass=testtpass

should be pretty simple just grab the params from your $_GET vars and use that to login the user

awesome logic

but how can i use UserIdentity in my controller?

Hi Bro,

I have a one line solution, i am using YUM extension and it worked for me just give a try may work for you too.

$identity = new YumUserIdentity($username, null);

 &#036;identity-&gt;authenticate(true);


 Yii::app()-&gt;user-&gt;login(&#036;identity,0);

here only you have to pass the username of the user to be logged in.

Thnaks a lot

is there any solution in user/rights module?

try to call UserIdentity rather than YumUserident

http://www.yiiframework.com/wiki/6/how-to-add-more-information-to-yii-app-user/

hope it will work.

Thank you very much

My view Url is

<?php echo CHtml::link(CHtml::tag(‘i’, array(‘class’=>‘glyphicon glyphicon-zoom-in icon-white’), ‘Login As’), array(“admin/loginas”,“id”=>$data->id),array(‘class’=>‘btn btn-success’)); ?>

My controller is


 public function actionLoginas($id)

	{

		   

		               $model=User::model()->findByPk($id);

				if(UserModule::isAdmin())

				{

		                $identity = new UserIdentity($model->username ,$model->password_show);

				$identity->authenticate();                

				if($identity->errorCode === UserIdentity::ERROR_NONE) 

				{

				  Yii::app()->user->login($identity, NULL);

				   Yii::app()->user->setFlash('profileMessage', "Your Are Successfully Login As ".$model->username." !");

				  $this->redirect(array(('/user/profile')));

				} else

				{

				  Yii::app()->user->setFlash('login_as_fail', "Your Are Failed to Login As ".$model->username." !");

				  $this->redirect(array('/user/profile'));

				}

				}else {throw new CHttpException(404,'The requested page does not exist.');}

   }