function bootstrap()
 {
     AuthenticationBackend::register(new LDAPAuthentication($this->getConfig()));
 }
 function searchStaff()
 {
     global $thisstaff;
     if (!$thisstaff) {
         Http::response(403, 'Login required for searching');
     } elseif (!$thisstaff->isAdmin()) {
         Http::response(403, 'Administrative privilege is required for searching');
     } elseif (!isset($_REQUEST['q'])) {
         Http::response(400, 'Query argument is required');
     }
     $users = array();
     foreach (AuthenticationBackend::getSearchDirectories() as $ab) {
         foreach ($ab->search($_REQUEST['q']) as $u) {
             $users[] = $u;
         }
     }
     return $this->json_encode($users);
 }
 function addUser($id, $userId = 0, $remote = false)
 {
     global $thisstaff;
     if (!$thisstaff) {
         Http::response(403, 'Login Required');
     } elseif (!($org = Organization::lookup($id))) {
         Http::response(404, 'Unknown organization');
     }
     $info = array();
     $info['title'] = __('Add User');
     $info['action'] = '#orgs/' . $org->getId() . '/add-user';
     $info['onselect'] = 'ajax.php/orgs/' . $org->getId() . '/add-user/';
     $info['lookup'] = false;
     if (AuthenticationBackend::getSearchDirectories()) {
         $info['lookup'] = 'remote';
     }
     if ($_POST) {
         if ($_POST['id']) {
             //Existing useer
             if (!($user = User::lookup($_POST['id']))) {
                 $info['error'] = __('Unknown user selected');
             } elseif ($user->getOrgId() == $org->getId()) {
                 $info['error'] = sprintf('%s already belongs to the organization', Format::htmlchars($user->getName()));
             }
         } else {
             //Creating new  user
             $form = UserForm::getUserForm()->getForm($_POST);
             if (!($user = User::fromForm($form))) {
                 $info['error'] = __('Error adding user - try again!');
             }
         }
         if (!$info['error'] && $user && $user->setOrganization($org)) {
             Http::response(201, $user->to_json());
         } elseif (!$info['error']) {
             $info['error'] = __('Unable to add user to the organization - try again');
         }
     } elseif ($remote && $userId) {
         list($bk, $userId) = explode(':', $userId, 2);
         if (!($backend = AuthenticationBackend::getSearchDirectoryBackend($bk)) || !($user_info = $backend->lookup($userId))) {
             Http::response(404, 'User not found');
         }
         $form = UserForm::getUserForm()->getForm($user_info);
     } elseif ($userId) {
         //Selected local user
         $user = User::lookup($userId);
     }
     if ($user && $user->getOrgId()) {
         if ($user->getOrgId() == $org->getId()) {
             $info['warn'] = __('User already belongs to this organization!');
         } else {
             $info['warn'] = __("Are you sure you want to change the user's organization?");
         }
     }
     ob_start();
     include STAFFINC_DIR . 'templates/user-lookup.tmpl.php';
     $resp = ob_get_contents();
     ob_end_clean();
     return $resp;
 }
Exemple #4
0
 static function allRegistered()
 {
     return array_merge(self::$_registry, parent::allRegistered());
 }
 function bootstrap()
 {
     AuthenticationBackend::register('HttpAuthentication');
 }