/** * @inheritdoc */ public function beforeSave($insert) { if ($insert) { $this->setAttribute('auth_key', Yii::$app->getSecurity()->generateRandomKey()); } if (!empty($this->password)) { $this->setAttribute('password_hash', Password::hash($this->password)); } return parent::beforeSave($insert); }
/** @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', \dektrium\user\helpers\Password::hash($this->password)); } return parent::beforeSave($insert); }
public function beforeSave($insert) { if ($insert) { $this->setAttribute('ref_link', substr(md5($this->username . time()), 0, 8)); $session = Yii::$app->session; $inviter_user_id = 0; if (($refLink = $session->get('ref')) !== null) { $invAR = static::getInviterARByRef($refLink); if ($invAR !== null) { $inviter_user_id = $invAR->getAttribute('id'); } } $this->setAttribute('inviter_user_id', $inviter_user_id); $this->setAttribute('last_visit_date', time()); } return parent::beforeSave($insert); }