I want to store the user’s IP address upon logging in. How do I do that?
Moreover, I don’t want this to affect the update_time attribute automatically updated by CTimeStampBehavior, as I want that to track other changes to the user’s record.
This is completely untested on my part, this framework is kind of huge if you need to know all of it’s workings. I’m a little vague on behaviors, so far I have only used a custom behavior when uploading files. However I think this might put you in the right direction.
Well, I tried disableBehavior() and couldn’t get it to work so I reread the docs on CTimestampBehavior and found out how to do it (in WebUser.php component):
public function login($identity)
{
$currentUser= Users::model()->findByPk($identity->Id);
$currentUser->last_logon = new CDbExpression('NOW()');
$currentUser->last_ip_address = ip2long(CHttpRequest::getUserHostAddress());
$currentUser->AutoTimeStamps->updateAttribute=NULL;
$currentUser->save();
$currentUser->AutoTimeStamps->updateAttribute='update_timestamp';
return parent::login($identity);
}
The above code will store the user’s logon timestamp and IP address without affecting the updated timestamp handled by the model’s CTimestampBehavior. Hope this helps someone else…