userService = $userService; $this->ldapService = $ldapService; if (! session()->exists('tmp')) { session(['tmp' => []]); } } /** * @throws \Exception */ #[RequiresPermission(UsersPermissions::IMPORT, global: true)] public function get(): Response { $this->tpl->assign('allUsers', $this->userService->getAll()); $this->tpl->assign('admin', true); $this->tpl->assign('roles', Roles::getRoles()); if (session()->exists('tmp.ldapUsers') && count(session('tmp.ldapUsers')) > 0) { $this->tpl->assign('allLdapUsers', session('tmp.ldapUsers')); $this->tpl->assign('confirmUsers', true); } return $this->tpl->displayPartial('users.importLdapDialog'); } /** * @throws BindingResolutionException */ #[RequiresPermission(UsersPermissions::IMPORT, global: true)] public function post($params): Response { // Password Submit to connect to ldap and retrieve users. Sets tmp session var if (isset($params['pwSubmit'])) { $bindUsername = $this->ldapService->extractLdapFromUsername(session('userdata.mail')); $members = $this->userService->fetchLdapMembers($bindUsername, $params['password']); if ($members !== false) { session(['tmp.ldapUsers' => $members]); $this->tpl->assign('allLdapUsers', session('tmp.ldapUsers')); $this->tpl->assign('confirmUsers', true); } else { $this->tpl->setNotification($this->language->__('notifications.username_or_password_incorrect'), 'error'); } } // Import/Update User Post if (isset($params['importSubmit'])) { if (is_array($params['users'])) { $this->userService->importSelectedLdapUsers(session('tmp.ldapUsers'), $params['users']); } } return $this->tpl->displayPartial('users.importLdapDialog'); } }