Hi guys,
i transformed the blog login to my own login using the UserIdentity, but when the user succesfully logged in and he will return a little later to the site he will see the login page again instead of automatticly redirect to the correct page.
below the neccecary scripts:
config:
'user'=>array(
'allowAutoLogin'=>true,
'loginUrl'=>array('login/login'),
'returnUrl'=>array('daytrip/list'),
),
model:
public function authenticate($attribute, $params)
{
if(!$this->hasErrors())
{
$identity = new UserIdentity($this->Username, $this->Password);
$identity->authenticate();
switch($identity->errorCode)
{
case UserIdentity::ERROR_NONE:
$duration = $this->RememberMe ? 3600 * 24 * 30 : 0; // 30 days
Yii::app()->user->login($identity, $duration);
break;
case UserIdentity::ERROR_UNKNOWN_IDENTITY:
$this->addError('Account', 'Account disabled.');
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('Username', 'Username is incorrect.');
break;
default: // UserIdentity::ERROR_PASSWORD_INVALID
$this->addError('Password', 'Password is incorrect.');
break;
}
}
}
controller:
public function actionLogin()
{
$login = new Login;
if(isset($_POST['Login']))
{
$login->attributes = $_POST['Login'];
if($login->validate())
$this->redirect(array('daytrip/list'));
}
$this->render('login', array('login' => $login));
}