hello i am new in yii.I want to validate the user after login in my actionLogin method i am getting my username, password, name and Id(primary key). I want to validate username, password and Id then to go into view user page.
following is my function. but i am having issue. plz guide me to solve this
You are not calling validate method, then how it will validate.
you have not mentioned what kind of problem are you facing?
Following sample code may help you
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()) {
//to get user id
$userid=Yii::app()->user->id;
//current time stamp
$timestamp=date('Y-m-d H:i:s');
//update last_login_time field in user table
User::model()->updateByPk($userid, array('last_login_time' =>$timestamp));
//$this->redirect(Yii::app()->user->returnUrl);
$this->redirect(array('programm/admin'));
}
}
// display the login form
$this->render('login',array('model'=>$model));
}