In yii, I am creating login module. After successful login I have to retrieve current login users userid and want to insert that userid into another 'logintransLog' table which is having userid as attribute with foreign key relationship. So in yii, how to retrieve current userid and insert it into another table? Please help me.....
I want to insert userid into table 'loginAttempt' if only userid is correct and password is wrong, in order to maintain records of how much time user had tried for login. So how can I implement this? I have actionlogin method as:
public function actionLogin()
{
$model=new LoginForm;
$command = Yii::app()->db->createCommand();
// 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())
{
$command->insert('trans', array(
'id'=>Yii::app()->user->getId(),
//'Ipaddress'=>Yii::app()->user->getIpaddress(),
));
$this->redirect(Yii::app()->user->returnUrl);
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
Please help me