@0neS // Контроллер Login
public function actionLogin()
{
if (Yii::app()->user->isGuest) {
if (isset($_POST['ajax']) && $_POST['ajax'] === 'UserLogin') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
$model=new UserLogin;
// collect user input data
if(isset($_POST['UserLogin']))
{
$model->attributes=$_POST['UserLogin'];
// validate user input and redirect to previous page if valid
if($model->validate()) {
$this->lastViset();
if (Yii::app()->getBaseUrl()."/index.php" === Yii::app()->user->returnUrl)
$this->redirect(Yii::app()->user->returnUrl);
else
$this->redirect('site/index');
}
}
// display the login form
$this->renderPartial('/user/login',array('model'=>$model));
} else
$this->redirect(Yii::app()->controller->module->returnUrl);
}
// Вид
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'UserLogin',
'enableAjaxValidation'=>true,
)); ?>
<h4>Вход</h4>
<hr>
<?php echo CHtml::errorSummary($model); ?>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<?php echo $form->textField($model,'username', array('placeholder'=>'Логин', 'class'=>'form-control')) ?>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<?php echo $form->passwordField($model,'password', array('placeholder'=>'Пароль', 'class'=>'form-control')) ?>
</div>
</div>
</div>
<?php echo CHtml::submitButton('Вход', array('class'=>'btn btn-primary')); ?>
<a href="<?php echo Yii::app()->createUrl('user/registration'); ?>" class="btn btn-default" data-dismiss="modal" type="button">Регистрация</a>
<?php $this->endWidget(); ?>