array( 'class' => 'yii\behaviors\AutoTimestamp', 'attributes' => array( ActiveRecord::EVENT_BEFORE_INSERT => array('create_time', 'update_time'), ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time', ), ), ); } public static function findIdentity($id) { return static::find($id); } public static function findByUsername($username) { return static::find(array('username' => $username, 'status' => static::STATUS_ACTIVE)); } public function getId() { return $this->id; } public function getAuthKey() { return $this->auth_key; } public function validateAuthKey($authKey) { return $this->auth_key === $authKey; } public function validatePassword($password) { return SecurityHelper::validatePassword($password, $this->password_hash); } public function rules() { return array( array('username', 'filter', 'filter' => 'trim'), array('username', 'required'), array('username', 'length', 'min' => 2, 'max' => 255), array('email', 'filter', 'filter' => 'trim'), array('email', 'required'), array('email', 'email'), array('email', 'unique', 'message' => 'This email address has already been taken.'), array('password', 'required'), array('password', 'length', 'min' => 6), ); } public function scenarios() { return array( 'signup' => array('username', 'email', 'password'), 'login' => array('username', 'password'), ); } public function beforeSave($insert) { if(parent::beforeSave($insert)) { if($this->isNewRecord) { if(!empty($this->password)) { $this->password_hash = SecurityHelper::generatePasswordHash($this->password); } } return true; } return false; } }