/** * 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')); } }
/** * The initialization event handler creates the captcha passphrase (if necessary). * * @return boolean Indicating Success */ public function _on_initialize() { $request_fieldname = "{$this->name}_session_key"; if (array_key_exists($request_fieldname, $_REQUEST)) { $this->_session_key = $_REQUEST[$request_fieldname]; } else { $hash = $_SERVER['REQUEST_URI']; $this->_session_key = md5($hash); } $session = new midcom_services_session($this->_session_domain); if (!$session->exists($this->_session_key)) { $phrase = midcom_admin_user_plugin::generate_password($this->length); $this->_passphrase = $phrase; $session->set($this->_session_key, $phrase); } else { $this->_passphrase = $session->get($this->_session_key); } return true; }
$time = time(); echo " <input type=\"hidden\" name=\"timestamp\" value=\"{$time}\" />\n"; echo " <input type=\"hidden\" name=\"ajax\" value=\"true\" />\n"; echo " <input type=\"hidden\" name=\"ajax-form\" value=\"false\" />\n"; } ?> </form> <?php } if (!is_numeric($n) || $n <= 0 || !is_numeric($length) || $length <= 0) { echo $data['l10n']->get('use positive numeric values'); } elseif ((int) $n > $max_amount || (int) $length > $max_length) { echo $data['l10n']->get('only up to 1000 passwords with maximum length of 16 characters'); } else { for ($i = 0; $i < $n; $i++) { $password = midcom_admin_user_plugin::generate_password($length, $no_similars, $strong); echo " <input type=\"text\" class=\"plain-text\" value=\"{$password}\" onclick=\"this.select();\" />\n"; echo "\n"; } } if (!isset($_GET['ajax-form'])) { if (isset($_GET['ajax'])) { ?> <script type="text/javascript"> // <![CDATA[ jQuery('#midcom_admin_user_generated_passwords_form').submit(function() { jQuery('#midcom_admin_user_generated_passwords_form').ajaxSubmit ( { target : jQuery('#midcom_admin_user_generated_passwords_random')