/** * Populate model object properties by the passed data * * @param array $data Data to set * * @return void */ protected function setModelProperties(array $data) { $adminAccessLevel = \XLite\Core\Auth::getInstance()->getAdminAccessLevel(); if (!empty($data['password'])) { // Encrypt password if if is not empty $data['password'] = \XLite\Core\Auth::encryptPassword($data['password']); } elseif (isset($data['password'])) { // Otherwise unset password to avoid passing empty password to the database unset($data['password']); } // Cannot change the status of own profile if ($this->isLoggedProfile()) { unset($data['status']); } // Apply the access level only during the profile creation if (!$this->isRegisterMode()) { unset($data['access_level']); } if (isset($data['forceChangePassword']) && is_string($data['forceChangePassword'])) { $data['forceChangePassword'] = (bool) $data['forceChangePassword']; } $isRoot = \XLite\Core\Auth::getInstance()->isPermissionAllowed(\XLite\Model\Role\Permission::ROOT_ACCESS); if (isset($data['roles']) && (!$isRoot || isset($data['access_level']) && $adminAccessLevel != $data['access_level'])) { unset($data['roles']); } $model = $this->getModelObject(); // Assign only role for admin $isAdmin = isset($data['access_level']) && $adminAccessLevel == $data['access_level'] || $model->getProfileId() && $model->isAdmin(); if ($isAdmin && $this->needSetRootAccess($this->getModelObject())) { $rootRole = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->findOneRoot(); if ($rootRole) { if (!isset($data['roles'])) { $data['roles'] = array(); } $data['roles'][] = $rootRole->getId(); } } if (isset($data['roles']) || isset($data['access_level']) && $adminAccessLevel != $data['access_level'] || $model->getProfileId() && !$model->isAdmin()) { // Remove old links foreach ($model->getRoles() as $role) { $role->getProfiles()->removeElement($model); } $model->getRoles()->clear(); } // Add new links if (isset($data['roles']) && is_array($data['roles'])) { $data['roles'] = array_unique($data['roles']); foreach ($data['roles'] as $rid) { $role = \XLite\Core\Database::getRepo('XLite\\Model\\Role')->find($rid); if ($role) { $model->addRoles($role); $role->addProfiles($model); } } } if (isset($data['roles'])) { unset($data['roles']); } parent::setModelProperties($data); }
/** * Generates password reset key * * @return string */ protected function generatePasswordResetKey() { $result = \XLite\Core\Auth::encryptPassword(microtime(), \XLite\Core\Auth::DEFAULT_HASH_ALGO); if (!empty($result) && 0 === strpos($result, \XLite\Core\Auth::DEFAULT_HASH_ALGO)) { $result = substr($result, 7); } return $result; }
/** * Process cart profile * * @param boolean $doCloneProfile Clone profile flag * * @return boolean */ protected function processCartProfile($doCloneProfile) { $isAnonymous = $this->isAnonymous(); if ($isAnonymous) { if (\XLite\Core\Session::getInstance()->order_create_profile) { // Create profile based on anonymous order profile $this->saveAnonymousProfile(); $this->loginAnonymousProfile(); $this->getCart()->getOrigProfile()->setPassword(\XLite\Core\Auth::encryptPassword(\XLite\Core\Session::getInstance()->createProfilePassword)); $isAnonymous = false; } elseif ($doCloneProfile) { $this->mergeAnonymousProfile(); } } elseif ($doCloneProfile) { // Clone profile $this->cloneProfile(); $isAnonymous = false; } return $isAnonymous; }
/** * Populate model object properties by the passed data * * @param array $data Data to set * * @return void */ protected function setModelProperties(array $data) { if (!empty($data['password'])) { $data['password'] = \XLite\Core\Auth::encryptPassword($data['password']); } elseif (isset($data['password'])) { unset($data['password']); } parent::setModelProperties($data); }
/** * Register anonymous profile * * @return void */ protected function doActionRegisterAsNew() { $result = false; $profile = $this->getModelForm()->getModelObject(); if ($profile && $profile->isPersistent() && $profile->getAnonymous() && !$profile->getOrder() && !\XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findUserWithSameLogin($profile)) { $profile->setAnonymous(false); $password = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->generatePassword(); $profile->setPassword(\XLite\Core\Auth::encryptPassword($password)); $result = $profile->update(); } if ($result) { // Send notification to the user \XLite\Core\Mailer::sendRegisterAnonymousCustomer($profile, $password); \XLite\Core\TopMessage::addInfo('The profile has been registered. The password has been sent to the user\'s email address'); } }
/** * Import password * * @param \XLite\Model\Profile $model Profile * @param string $value Value * @param integer $index Index * * @return void */ protected function importPasswordColumn(\XLite\Model\Profile $model, $value, $index) { if (!empty($value)) { $model->setPassword(\XLite\Core\Auth::encryptPassword($value)); // Schedule to delete files after import finished $this->importer->getOptions()->clearImportDir = true; } }