/** * 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; }
/** * 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_manageRequest($handler_id, $args, &$data) { $_MIDCOM->auth->require_admin_user(); $this->_request_data['name'] = "fi.kilonkipinat.accountregistration"; $this->_update_breadcrumb_line($handler_id); $title = $this->_l10n_midcom->get('fi.kilonkipinat.accountregistration'); $_MIDCOM->set_pagetitle(":: {$title}"); $prefix = $this->_request_data['prefix']; $request = new fi_kilonkipinat_accountregistration_accountrequest_dba(trim($args[0])); if (!isset($request) || !isset($request->guid) || $request->guid == '' || $request->guid != $args[0]) { debug_push_class(__CLASS__, __FUNCTION__); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to load request, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } $this->_request_data['request'] = $request; if (isset($_POST) && isset($_POST['username'])) { if (isset($_POST['isduplicate']) && $_POST['isduplicate'] == '1') { $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_INVALID; $request->update(); $message['title'] = $this->_l10n_midcom->get("Poistettu"); $message['content'] = $this->_l10n_midcom->get("Kyseinen hakemus on merkattu duplikaatiksi, ts poistettu."); } else { if (isset($_POST['merge_user_guid']) && $_POST['merge_user_guid'] != '') { $person = new fi_kilonkipinat_account_person_dba(trim($_POST['merge_user_guid'])); } else { $qb = fi_kilonkipinat_account_person_dba::new_query_builder(); $qb->add_constraint('username', '=', trim($_POST['username'])); $results = $qb->execute(); if (count($results) > 0) { $message['title'] = $this->_l10n_midcom->get("error"); $message['content'] = $this->_l10n_midcom->get("Kyseinen tyyppi on jo olemassa"); } else { $person = new fi_kilonkipinat_account_person_dba(); $person->username = trim($_POST['username']); $person->create(); } } if (isset($person)) { $person->firstname = $request->firstname; $person->lastname = $request->lastname; $person->email = $request->email; $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; $person->update(); if (isset($_POST['add_to_groups']) && count($_POST['add_to_groups']) > 0) { foreach ($_POST['add_to_groups'] as $group_guid) { $group = new midcom_db_group($group_guid); if (isset($group) && isset($group->guid) && $group->guid == $group_guid) { $membership = new midcom_db_member(); $membership->uid = $person->id; $membership->gid = $group->id; $membership->create(); } } } $person->set_privilege('midgard:owner', "user:{$person->guid}"); $request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_RESOLVED; $request->personGuid = $person->guid; $request->update(); $subject = 'Tunnuksesi kilonkipinat.fi-sivustolle'; $body = sprintf('Hei %s', $person->firstname); $body .= "\n\n"; $body .= sprintf('käyttäjätunnus: %s', $person->username); $body .= "\n\n"; $body .= sprintf('salasana: %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; $message = array(); if ($mail->send('mail')) { $message['title'] = $this->_l10n_midcom->get("Onnistui"); $message['content'] = ''; } else { $message['title'] = $this->_l10n_midcom->get("error"); $message['content'] = $this->_l10n_midcom->get("Oops, something went wrong."); } } } $this->_request_data['message'] = $message; } return true; }
<?php $username = ''; switch ($data['config']->get('username_generation')) { default: case 'firstname.lastname': $username = fi_kilonkipinat_accountregistration_viewer::cleanUserNameStr($request->firstname); $username .= '.'; $username .= fi_kilonkipinat_accountregistration_viewer::cleanUserNameStr($request->lastname); break; case 'firstname_lastname': $username = fi_kilonkipinat_accountregistration_viewer::cleanUserNameStr($request->firstname); $username .= '_'; $username .= fi_kilonkipinat_accountregistration_viewer::cleanUserNameStr($request->lastname); break; case 'email': $username = fi_kilonkipinat_accountregistration_viewer::cleanUserNameStr($email); break; } ?> <div id="fi_kilonkipinat_accountregistration_search_user_results"></div> <table> <tr> <th>Käyttäjätunnus</th> <td><input type="text" name="username" value="&(username);" id="fi_kilonkipinat_accountregistration_username" /></td> </tr> <tr> <th>Liitä tunnukseen</th> <td> <input type="hidden" name="merge_user_guid" id="fi_kilonkipinat_accountregistration_merge_user_guid" /> <input type="text" name="search_user" id="fi_kilonkipinat_accountregistration_search_user_text" /> <a href="#" onclick="searchUser(); return false;">Hae</a> </td>