Hello everybody,
having a little issue here. I wanna update the field ‘lastactive’ field in my database after a successful login. This is my changed UserIdentity::authenticate() method:
private $_id;
public function authenticate()
{
// $this->username === provided email in call
$dbuser=User::model()->findByAttributes(array('email'=>$this->username));
if($dbuser === null) // no user was found in the database
$this->errorCode=self::ERROR_USERNAME_INVALID;
if(!CPasswordHelper::verifyPassword($this->password, $dbuser->password)) // wrong password
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else { // OK!
$this->setLoginAttributes($dbuser);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function setLoginAttributes($dbuser)
{
$this->_id = $dbuser->id;
$this->setState('first_name', $dbuser->first_name);
$this->setState('last_name', $dbuser->last_name);
$this->setState('status', $dbuser->status);
$dbuser->lastactive = New CDbExpression('NOW()');
$dbuser->save(array('lastactive'));
}
public function getId()
{
return $this->_id;
}
But the save operation doesn’t work. So I checked if it does with SaveAttributes(array(‘lastactive’)), and it does. So I assumed it’s a problem with my validation rules. I checked them one after another, and turned out the one who causes the problem is the fourth from the top about my birthday column:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, password', 'required'),
array('email', 'email'),
array('email', 'unique'),
array('birthday', 'date'),
array('active, online, address_id', 'numerical', 'integerOnly'=>true),
array('first_name, last_name, email, image', 'length', 'max'=>255),
array('about', 'length', 'max'=>4000),
array('status', 'length', 'max'=><img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,
//array('password', 'length', 'is'=>60),
array('birthday, joined, lastactive', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, first_name, last_name, email, birthday, about, joined, lastactive, status, active, image, online, password, address_id', 'safe', 'on'=>'search'),
);
}
Can somebody explain me why the reason for that?
Thanks in advance!