Пример #1
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('midcom.core');
     $person = new midcom_db_person();
     $stat = $person->create();
     $this->assertTrue($stat);
     $this->register_object($person);
     $person = new midcom_db_person($person->guid);
     $this->assertEquals('person #' . $person->id, $person->name);
     $this->assertEquals('person #' . $person->id, $person->rname);
     $person->firstname = ' Firstname ';
     $person->lastname = ' Lastname ';
     $stat = $person->update();
     $this->assertTrue($stat);
     $this->assertEquals('Firstname Lastname', $person->name);
     $this->assertEquals('Lastname, Firstname', $person->rname);
     $group = $this->create_object('midcom_db_group');
     $attributes = array('gid' => $group->id, 'uid' => $person->id);
     $member = $this->create_object('midcom_db_member', $attributes);
     $stat = $person->delete();
     $this->assertTrue($stat);
     $qb = midcom_db_member::new_query_builder();
     $qb->add_constraint('id', '=', $member->id);
     $this->assertEquals(0, $qb->count());
     midcom::get('auth')->drop_sudo();
 }
Пример #2
0
 /**
  * The handler for the index article.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_approveReset($handler_id, $args, &$data)
 {
     $message = array();
     $reset_request = new fi_kilonkipinat_accountregistration_resetrequest_dba(trim($args[0]));
     if (isset($reset_request) && isset($reset_request->guid) && $reset_request->guid == trim($args[0]) && $reset_request->status == FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW) {
         $_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration');
         $person = new midcom_db_person($reset_request->person);
         if (isset($person) && isset($person->guid) && $person->guid != '' && $person->id == $reset_request->person) {
             $password = fi_kilonkipinat_accountregistration_viewer::generatePassword($this->_config->get('password_length'));
             // Enforce crypt mode
             $salt = chr(rand(64, 126)) . chr(rand(64, 126));
             $crypt_password = crypt($password, $salt);
             $person->password = $crypt_password;
             if ($person->update()) {
                 $reset_request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_RESOLVED;
                 $reset_request->update();
                 $message['title'] = "Onnistui";
                 $message['content'] = "Tarkista sähköpostisi";
                 $subject = sprintf('Uusi salasananne', $_SERVER['SERVER_NAME']);
                 $body = sprintf('Hei %s', $person->firstname);
                 $body .= "\n\n";
                 $body .= sprintf('Uusi salasanne on %s', $password);
                 $mail = new org_openpsa_mail();
                 $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>';
                 $mail->to = $person->firstname . ' ' . $person->lastname . ' <' . $person->email . '>';
                 $mail->body = $body;
                 $mail->subject = $subject;
                 if ($mail->send('mail')) {
                     $message['title'] = "Onnistui";
                     $message['content'] = "Tarkista sähköpostisi.";
                 } else {
                     $message['title'] = "Virhe";
                     $message['content'] = "Oho, jotain meni pieleen";
                 }
             }
         }
         $_MIDCOM->auth->drop_sudo('fi.kilonkipinat.accountregistration');
     } else {
         $message['title'] = "Virhe";
         $message['content'] = "Ei löytynyt pyyn";
     }
     $this->_request_data['message'] = $message;
     return true;
 }
Пример #3
0
 private function _batch_process()
 {
     foreach ($_POST['midcom_admin_user'] as $person_id) {
         try {
             if (is_numeric($person_id)) {
                 $person = new midcom_db_person((int) $person_id);
             } else {
                 $person = new midcom_db_person($person_id);
             }
         } catch (midcom_error $e) {
             continue;
         }
         switch ($_POST['midcom_admin_user_action']) {
             case 'removeaccount':
                 if (!$this->_config->get('allow_manage_accounts')) {
                     break;
                 }
                 $person->parameter('midcom.admin.user', 'username', $person->username);
                 $person->username = '';
                 $person->password = '';
                 if ($person->update()) {
                     midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user account revoked for %s'), $person->name));
                 }
                 break;
             case 'groupadd':
                 if (isset($_POST['midcom_admin_user_group'])) {
                     $member = new midcom_db_member();
                     $member->uid = $person->id;
                     $member->gid = (int) $_POST['midcom_admin_user_group'];
                     if ($member->create()) {
                         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('user %s added to group'), $person->name));
                     }
                 }
                 break;
         }
     }
 }
Пример #4
0
 /**
  * Internal helper for processing the batch change of passwords
  */
 private function _process_batch_change()
 {
     // Set the mail commo parts
     $mail = new org_openpsa_mail();
     $mail->from = $this->_config->get('message_sender');
     $mail->encoding = 'UTF-8';
     // Success switch
     $success = true;
     // Get the context prefix
     $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
     // Change every user or continue to next on failure - failures will show UI messages
     foreach ($_POST['midcom_admin_user'] as $id) {
         try {
             $person = new midcom_db_person($id);
         } catch (midcom_error $e) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to get the user with id %s'), $id), 'error');
             $success = false;
             continue;
         }
         // This shortcut is used in case of errors
         $person_edit_url = "<a href=\"{$prefix}__mfa/asgard_midcom.admin.user/edit/{$person->guid}\">{$person->name}</a>";
         // Cannot send the email if address is not specified
         if (!$person->email) {
             midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('no email address defined for %s'), $person_edit_url), 'error');
             continue;
         }
         // Recipient
         $mail->to = $person->email;
         // Store the old password
         $person->set_parameter('midcom.admin.user', 'old_password', $person->password);
         // Get a new password
         $password = midcom_admin_user_plugin::generate_password(8);
         $mail->body = $_POST['body'];
         $mail->subject = $_POST['subject'];
         $mail->parameters = array('PASSWORD' => $password, 'FROM' => $this->_config->get('message_sender'), 'LONGDATE' => strftime('%c'), 'SHORTDATE' => strftime('%x'), 'TIME' => strftime('%X'), 'PERSON' => $person);
         // Send the message
         if ($mail->send()) {
             // Set the password
             $person->password = "******";
             if (!$person->update()) {
                 midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), sprintf($this->_l10n->get('failed to update the password for %s'), $person_edit_url));
                 $success = false;
             }
         } else {
             throw new midcom_error("Failed to send the mail, SMTP returned error " . $mail->get_error_message());
         }
     }
     // Show UI message on success
     if ($success) {
         midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), $this->_l10n->get('passwords updated and mail sent'));
     }
 }