Inheritance: extends Pimcore\Model\User\Listing\AbstractListing
Example #1
0
 /**
  * @throws \Exception
  */
 public function init()
 {
     $conf = Config::getSystemConfig();
     if (!$conf->webservice->enabled) {
         throw new \Exception("Webservice API isn't enabled");
     }
     if (!$this->getParam("apikey") && $_COOKIE["pimcore_admin_sid"]) {
         $user = Authentication::authenticateSession();
         if (!$user instanceof User) {
             throw new \Exception("User is not valid");
         }
     } else {
         if (!$this->getParam("apikey")) {
             throw new \Exception("API key missing");
         } else {
             $apikey = $this->getParam("apikey");
             $userList = new User\Listing();
             $userList->setCondition("apiKey = ? AND type = ? AND active = 1", array($apikey, "user"));
             $users = $userList->load();
             if (!is_array($users) or count($users) !== 1) {
                 throw new \Exception("API key error.");
             }
             if (!$users[0]->getApiKey()) {
                 throw new \Exception("Couldn't get API key for user.");
             }
             $user = $users[0];
         }
     }
     \Zend_Registry::set("pimcore_admin_user", $user);
     parent::init();
 }
Example #2
0
 /**
  *
  */
 public function configureOptions()
 {
     $list = new Model\User\Listing();
     $list->setOrder("asc");
     $list->setOrderKey("name");
     $users = $list->load();
     $options = array();
     if (is_array($users) and count($users) > 0) {
         foreach ($users as $user) {
             if ($user instanceof Model\User) {
                 $value = $user->getName();
                 $first = $user->getFirstname();
                 $last = $user->getLastname();
                 if (!empty($first) or !empty($last)) {
                     $value .= " (" . $first . " " . $last . ")";
                 }
                 $options[] = array("value" => $user->getId(), "key" => $value);
             }
         }
     }
     $this->setOptions($options);
 }
Example #3
0
 public function searchAction()
 {
     $q = "%" . $this->getParam("query") . "%";
     $list = new User\Listing();
     $list->setCondition("name LIKE ? OR firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR id = ?", [$q, $q, $q, $q, intval($this->getParam("query"))]);
     $list->setOrder("ASC");
     $list->setOrderKey("name");
     $list->load();
     $users = [];
     if (is_array($list->getUsers())) {
         foreach ($list->getUsers() as $user) {
             if ($user instanceof User && $user->getId() && $user->getName() != "system") {
                 $users[] = ["id" => $user->getId(), "name" => $user->getName(), "email" => $user->getEmail(), "firstname" => $user->getFirstname(), "lastname" => $user->getLastname()];
             }
         }
     }
     $this->_helper->json(["success" => true, "users" => $users]);
 }
Example #4
0
 /**
  *
  */
 public function delete()
 {
     // delete all childs
     $list = new Listing();
     $list->setCondition("parentId = ?", $this->getId());
     $list->load();
     if (is_array($list->getUsers())) {
         foreach ($list->getUsers() as $user) {
             $user->delete();
         }
     }
     // now delete the current user
     $this->getDao()->delete();
     \Pimcore\Cache::clearAll();
 }
 public function getSystemAction()
 {
     $this->checkPermission("system_settings");
     $values = Config::getSystemConfig();
     if (($handle = fopen(PIMCORE_PATH . "/config/timezones.csv", "r")) !== FALSE) {
         while (($rowData = fgetcsv($handle, 10000, ",", '"')) !== false) {
             $timezones[] = $rowData[0];
         }
         fclose($handle);
     }
     $locales = Tool::getSupportedLocales();
     $languageOptions = array();
     foreach ($locales as $short => $translation) {
         if (!empty($short)) {
             $languageOptions[] = array("language" => $short, "display" => $translation . " ({$short})");
             $validLanguages[] = $short;
         }
     }
     $valueArray = $values->toArray();
     $valueArray['general']['validLanguage'] = explode(",", $valueArray['general']['validLanguages']);
     //for "wrong" legacy values
     if (is_array($valueArray['general']['validLanguage'])) {
         foreach ($valueArray['general']['validLanguage'] as $existingValue) {
             if (!in_array($existingValue, $validLanguages)) {
                 $languageOptions[] = array("language" => $existingValue, "display" => $existingValue);
             }
         }
     }
     //cache exclude patterns - add as array
     if (!empty($valueArray['cache']['excludePatterns'])) {
         $patterns = explode(",", $valueArray['cache']['excludePatterns']);
         if (is_array($patterns)) {
             foreach ($patterns as $pattern) {
                 $valueArray['cache']['excludePatternsArray'][] = array("value" => $pattern);
             }
         }
     }
     //remove password from values sent to frontend
     $valueArray['database']["params"]['password'] = "******";
     //admin users as array
     $adminUsers = array();
     $userList = new Model\User\Listing();
     $userList->setCondition("admin = 1 and email is not null and email != ''");
     $users = $userList->load();
     if (is_array($users)) {
         foreach ($users as $user) {
             $adminUsers[] = array("id" => $user->getId(), "username" => $user->getName());
         }
     }
     $adminUsers[] = array("id" => "", "username" => "-");
     $response = array("values" => $valueArray, "adminUsers" => $adminUsers, "config" => array("timezones" => $timezones, "languages" => $languageOptions, "client_ip" => Tool::getClientIp(), "google_private_key_exists" => file_exists(\Pimcore\Google\Api::getPrivateKeyPath()), "google_private_key_path" => \Pimcore\Google\Api::getPrivateKeyPath()));
     $this->_helper->json($response);
 }
Example #6
0
 /**
  * Returns a list of users given an array of ID's
  * if an ID is a role, all users associated with that role
  * will also be returned.
  * @param $userIds
  */
 private static function getNotificationUsers($userIds)
 {
     $notifyUsers = [];
     //get roles
     $roleList = new User\Role\Listing();
     $roleList->setCondition('id in (?)', [implode(',', $userIds)]);
     foreach ($roleList->load() as $role) {
         $userList = new User\Listing();
         $userList->setCondition('FIND_IN_SET(?, roles) > 0', [$role->getId()]);
         foreach ($userList->load() as $user) {
             if ($user->getEmail()) {
                 $notifyUsers[] = $user;
             }
         }
     }
     unset($roleList, $user, $role);
     //get users
     $roleList = new User\Listing();
     $roleList->setCondition('id in (?)', [implode(',', $userIds)]);
     foreach ($roleList->load() as $user) {
         /**
          * @var User $user
          */
         if ($user->getEmail()) {
             $notifyUsers[] = $user;
         }
     }
     return $notifyUsers;
 }