session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Session object destruction failed
код в контроллере:
Код: Выделить всё
if(isset($_POST['LoginForm']))
{
$login->attributes=$_POST['LoginForm'];
//проверяем данных
if($login->validate() && $login->login()){
$this->redirect('user/account/profile');
}
}
$this->render('index',array('login'=>$login,'register'=>$register));
Код: Выделить всё
<?php
/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends BFormModel
{
public $email;
public $password;
public $rememberMe;
private $_identity;
/**
* Declares the validation rules.
* The rules state that login and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// login and password are required
array('email, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
//проверяем email по принципу
array('email', 'email'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe'=>Yii::t('UserModule.login', 'Запомнить меня'),
'password'=>Yii::t('UserModule.login', 'Ваш пароль'),
'email'=>Yii::t('UserModule.login', 'Ваш электронный адрес'),
);
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
$this->_identity=new UserIdentity($this->email,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password',Yii::t('UserModule.login','Неверный электронный адрес пользователя или пароль.'));
}
/**
* Logs in the user using the given login and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->email,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
}
Код: Выделить всё
class UserIdentity extends CUserIdentity
{
private $_id;
/**
* Authenticates a user.
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = User::model()->find('LOWER(email)=?',array(strtolower($this->username)));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->username=$user->name.' '.$user->lastname; /** Странно почему то patronymic берется, надо разбиратся потом */
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
/**
* @return integer the ID of the user record
*/
public function getId()
{
return $this->_id;
}
}
Еще один момент: когда открывается страница ошибок и если обновить страницу то тогда попадают в страницу profile