login

Hello! I am starting with yii framework I am programming in version 1.9 and what I try to do is that my main page is the login, and when a user is logged in I redirect to the project forms with their permissions of each user

this is my login code:




<?php

/* @var $this SiteController */

/* @var $model LoginForm */

/* @var $form CActiveForm  */





?>

<style>


body h1{

  

  

  font-style:oblique;

  font-weight:bold;

  font-size:4em;

  font-color:#C49AFF;

  font-family:'Helvetica','Verdana','Monaco',sans-serif;

}


body{

	top: -20px;

	left: -20px;

	right: -40px;

	bottom: -40px;

	width: auto;

	height: auto;

	

	background-image: url(fondo.jpg);

	background-size: cover;

	

	

}





</style>

<font color="White">

<h1>Login</h1>




<div class="form-horizontal">

<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'login-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnSubmit'=>true,

	),

	'action' => array("site/login"),

    )); ?>


	


<div class="control-group">

		<?php echo $form->labelEx($model,'username', array('class'=>'control-label')); ?>

		<div class="controls">

			<?php echo $form->textField($model,'username'); ?>

	    	<?php echo $form->error($model,'username'); ?>

		</div>

	</div>

	<div class="control-group">

		<?php echo $form->labelEx($model,'password', array('class'=>'control-label')); ?>

		<div class="controls">

			<?php echo $form->passwordField($model,'password'); ?>

			<?php echo $form->error($model,'password'); ?>

		</div>

		

	</div>


	


	<div class="control-group ">

		<div class="controls">

         	<?php echo CHtml::submitButton('Login', array('class'=>'btn btn-primary')) ?>

		     <a href="#" class="facebook_connect radius button facebook"><i class="fa fa-facebook-square"></i>			

		</div>

	</div>


<?php $this->endWidget(); ?>

</div><!-- form -->




and this is my SiteController:

public function actionLogin()

	{

		

		$model=new LoginForm;


		// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}


		// collect user input data

		if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

			// validate user input and redirect to the previous page if valid

			if($model->validate() && $model->login());

				$this->redirect(Yii::app()->user->returnUrl);

		}

		// display the login form

		$this->render('login',array('model'=>$model));

	}



In advance thanks for the help

What’s the question?

how can I do so that by clicking the login button I redirected to a form or another page?

All you need is to set redirection url (one that you want user to redirect). Something like :




if($model->validate() && $model->login());

    $this->redirect('controller/action');

}



1 Like

thank you very much :D