/** * */ public function beforeSave() { if (!parent::beforeSave()) { return false; } // generate an api key if ($this->api_status && empty($this->dbAttributes['api_status'])) { $plainApiKey = $this->getApiKey(); if ($plainApiKey) { $this->api_key = $this->hashPassword($plainApiKey); } } if (!$this->api_status) { $this->api_key = null; } // if they have no password - assign password so that forgot password links work if ($this->isNewRecord && !$this->password) { $this->password = $this->hashPassword(md5(uniqid('', true))); } return true; }