/** @inheritdoc */ public function beforeSave($insert) { if ($insert) { $this->setAttribute('auth_key', Yii::$app->security->generateRandomString()); if (Yii::$app instanceof WebApplication) { $this->setAttribute('registration_ip', Yii::$app->request->userIP); } } if (!empty($this->password)) { $this->setAttribute('password_hash', Password::hash($this->password)); } if (empty($this->lang)) { $this->setAttribute('lang', Yii::$app->language); } return parent::beforeSave($insert); }