예제 #1
0
파일: viewer.php 프로젝트: nemein/openpsa
 /**
  * Helper function that lists options for the person filter
  */
 public function get_person_options()
 {
     $qb_persons = midcom_db_person::new_query_builder();
     midcom_core_account::add_username_constraint($qb_persons, '<>', '');
     $person_array = array();
     $persons = $qb_persons->execute();
     foreach ($persons as $person) {
         $person_array[$person->id] = $person->get_label();
     }
     return $person_array;
 }
예제 #2
0
파일: edit.php 프로젝트: nemein/openpsa
 /**
  * Handler method for listing style elements for the currently used component topic
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     $this->_person = new midcom_db_person($args[0]);
     $this->_person->require_do('midgard:update');
     if ($handler_id == '____mfa-asgard_midcom.admin.user-user_edit_password') {
         if (!$this->_config->get('allow_manage_accounts')) {
             throw new midcom_error('Account management is disabled');
         }
         $this->_schemadb_name = 'schemadb_account';
     }
     $data['view_title'] = sprintf(midcom::get('i18n')->get_string('edit %s', 'midcom.admin.user'), $this->_person->name);
     midcom::get('head')->set_pagetitle($data['view_title']);
     $this->_prepare_toolbar($data, $handler_id);
     $this->add_breadcrumb("__mfa/asgard_midcom.admin.user/", $data['view_title']);
     // Add jQuery Form handling for generating passwords with AJAX
     midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/jQuery/jquery.form.js');
     // Manually check the username to prevent duplicates
     if (isset($_REQUEST['midcom_helper_datamanager2_save']) && isset($_POST['username'])) {
         // If there was a username, check against duplicates
         if ($_POST['username']) {
             $qb = midcom_db_person::new_query_builder();
             $qb->add_constraint('username', '=', $_POST['username']);
             $qb->add_constraint('guid', '<>', $this->_person->guid);
             // If matches were found, add an error message
             if ($qb->count() > 0) {
                 midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midcom.admin.user', 'midcom.admin.user'), sprintf(midcom::get('i18n')->get_string('username %s is already in use', 'midcom.admin.user'), $_REQUEST['username']));
                 unset($_POST['midcom_helper_datamanager2_save']);
                 unset($_REQUEST['midcom_helper_datamanager2_save']);
             }
         } else {
             // Remove the password requirement if there is no username present
             foreach ($this->_schemadb as $key => $schema) {
                 if (isset($schema->fields['password'])) {
                     $this->_schemadb[$key]->fields['password']['widget_config']['require_password'] = false;
                 }
             }
         }
     }
     $data['controller'] = $this->get_controller('simple', $this->_person);
     switch ($data['controller']->process_form()) {
         case 'save':
             // Show confirmation for the user
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('person %s saved'), $this->_person->name));
             return new midcom_response_relocate("__mfa/asgard_midcom.admin.user/edit/{$this->_person->guid}/");
         case 'cancel':
             return new midcom_response_relocate('__mfa/asgard_midcom.admin.user/');
     }
 }
예제 #3
0
파일: list.php 프로젝트: nemein/openpsa
 private function _list_persons()
 {
     if (isset($_REQUEST['midcom_admin_user_search'])) {
         // Run the person-seeking QB
         $qb = midcom_db_person::new_query_builder();
         $qb->begin_group('OR');
         foreach ($this->_request_data['search_fields'] as $field) {
             $qb->add_constraint($field, 'LIKE', "{$_REQUEST['midcom_admin_user_search']}%");
         }
         $qb->end_group('OR');
         $qb->add_order('lastname');
         $qb->add_order('firstname');
         $this->_persons = $qb->execute();
     } else {
         // List all persons if there are less than N of them
         $qb = midcom_db_person::new_query_builder();
         if ($qb->count_unchecked() < $this->_config->get('list_without_search')) {
             $qb->add_order('lastname');
             $qb->add_order('firstname');
             $this->_persons = $qb->execute();
         }
     }
 }
예제 #4
0
파일: email.php 프로젝트: nemein/openpsa
 private function _find_email_person($email, $prefer_user = true)
 {
     // TODO: Use the new helpers for finding persons by email (a person might have multiple ones...)
     $qb = midcom_db_person::new_query_builder();
     $qb->add_constraint('email', '=', $email);
     $results = $qb->execute();
     if (empty($results)) {
         return false;
     }
     if (!$prefer_user) {
         return $results[0];
     }
     foreach ($results as $person) {
         if (!empty($person->username)) {
             return $person;
         }
     }
     return $person;
 }
예제 #5
0
 function emailimport_find_person($email, $prefer_user = true)
 {
     $qb = midcom_db_person::new_query_builder();
     $qb->add_constraint('email', '=', $email);
     $results = $qb->execute();
     if (empty($results)) {
         return false;
     }
     if (!$prefer_user) {
         return $results[0];
     }
     foreach ($results as $person) {
         if (!empty($person->username)) {
             return $person;
         }
     }
     return $person;
 }
예제 #6
0
파일: cleanup.php 프로젝트: nemein/openpsa
<?php

midcom::get('auth')->require_admin_user();
midcom::get()->disable_limits();
//Note: You have to run this multiple times, offset does not take deletions into account
$chunk_size = 1000;
$offset = 0;
$valid_persons = array();
$valid_targets = array();
$invalid_targets = array();
$person_qb = midcom_db_person::new_query_builder();
$person_qb->include_deleted();
$persons = $person_qb->execute();
foreach ($persons as $person) {
    $valid_persons[] = $person->id;
    $valid_targets[] = $person->guid;
}
unset($persons);
while (@ob_end_flush()) {
}
echo "<pre>\n";
flush();
do {
    $qb = midcom_helper_activitystream_activity_dba::new_query_builder();
    $qb->add_constraint('actor', 'NOT IN', $valid_persons);
    $qb->add_constraint('actor', '<>', 0);
    $qb->set_limit($chunk_size);
    $results = $qb->execute();
    echo "Deleting " . sizeof($results) . " entries for purged persons\n";
    flush();
    foreach ($results as $result) {
예제 #7
0
 public static function get_person_by_formdata($data)
 {
     if (empty($data['username']) || empty($data['password'])) {
         return false;
     }
     midcom::get('auth')->request_sudo('org.openpsa.user');
     $qb = midcom_db_person::new_query_builder();
     midcom_core_account::add_username_constraint($qb, '=', $_POST['username']);
     $results = $qb->execute();
     midcom::get('auth')->drop_sudo();
     if (sizeof($results) != 1) {
         return false;
     }
     return $results[0];
 }
예제 #8
0
파일: fetch.php 프로젝트: nemein/openpsa
 /**
  * Parses author formats used by different feed standards and
  * tries to match to persons in database.
  *
  * @param Array $item Feed item as provided by MagpieRSS
  * @return MidgardPerson Person object matched, or null
  */
 function match_item_author($item)
 {
     // Parse the item for author information
     $author_info = $this->parse_item_author($item);
     // Start matching the information found to person entries in the database
     $matched_person = null;
     if (isset($author_info['email'])) {
         // Email is a pretty good identifier, start with it
         $person_qb = midcom_db_person::new_query_builder();
         $person_qb->add_constraint('email', '=', $author_info['email']);
         $persons = $person_qb->execute();
         if (count($persons) > 0) {
             $matched_person = $persons[0];
         }
     }
     if (is_null($matched_person) && isset($author_info['username'])) {
         // Email is a pretty good identifier, start with it
         $person_qb = midcom_db_person::new_query_builder();
         $person_qb->add_constraint('username', '=', strtolower($author_info['username']));
         $persons = $person_qb->execute();
         if (count($persons) > 0) {
             $matched_person = $persons[0];
         }
     }
     if (is_null($matched_person) && isset($author_info['full_name'])) {
         $name_parts = explode(' ', $author_info['full_name']);
         if (count($name_parts) > 1) {
             // We assume the western format Firstname Lastname
             $firstname = $name_parts[0];
             $lastname = $name_parts[1];
             $person_qb = midcom_db_person::new_query_builder();
             $person_qb->add_constraint('firstname', '=', $firstname);
             $person_qb->add_constraint('lastname', '=', $lastname);
             $persons = $person_qb->execute();
             if (count($persons) > 0) {
                 $matched_person = $persons[0];
             }
         }
     }
     return $matched_person;
 }
예제 #9
0
 /**
  * This is an internal helper function, resetting the password to a randomly generated one.
  */
 private function _reset_password()
 {
     if (!midcom::get('auth')->request_sudo($this->_component)) {
         throw new midcom_error('Failed to request sudo privileges.');
     }
     $qb = midcom_db_person::new_query_builder();
     if (array_key_exists('username', $this->_controller->datamanager->types)) {
         $user = midcom::get('auth')->get_user_by_name($this->_controller->datamanager->types['username']->value);
         if (!$user) {
             midcom::get('auth')->drop_sudo();
             throw new midcom_error("Cannot find user. For some reason the QuickForm validation failed.");
         }
         $qb->add_constraint('guid', '=', $user->guid);
     }
     if (array_key_exists('email', $this->_controller->datamanager->types)) {
         $qb->add_constraint('email', '=', $this->_controller->datamanager->types['email']->value);
     }
     $results = $qb->execute();
     if (sizeof($results) != 1) {
         midcom::get('auth')->drop_sudo();
         throw new midcom_error("Cannot find user. For some reason the QuickForm validation failed.");
     }
     $person = $results[0];
     $account = new midcom_core_account($person);
     // Generate a random password
     $length = max(8, $this->_config->get('password_minlength'));
     $password = org_openpsa_user_accounthelper::generate_password($length);
     $account->set_password($password);
     if (!$account->save()) {
         midcom::get('auth')->drop_sudo();
         throw new midcom_error("Could not update the password: " . midcom_connection::get_error_string());
     }
     midcom::get('auth')->drop_sudo();
     $this->_send_reset_mail($person, $password);
 }