function _on_execute() { debug_push_class(__CLASS__, __FUNCTION__); if (!$_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration')) { $msg = "Could not get sudo, aborting operation, see error log for details"; $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_pop(); return; } $time_for_old = date('Y-m-d 00:00', time() - 3600 * 24); $qb_resetrequests = fi_kilonkipinat_accountregistration_resetrequest_dba::new_query_builder(); $qb_resetrequests->add_constraint('metadata.revised', '<', $time_for_old); $qb_resetrequests->add_constraint('status', '=', FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW); $results = $qb_resetrequests->execute(); foreach ($results as $result) { $result->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_INVALID; $result->update(); } $time_for_old = date('Y-m-d 00:00', time() - 3600 * 24 * 31); $qb_accounts = fi_kilonkipinat_accountregistration_accountrequest_dba::new_query_builder(); $qb_accounts->add_constraint('metadata.revised', '<', $time_for_old); $qb_accounts->add_constraint('status', '=', FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_NEW); $results2 = $qb_accounts->execute(); foreach ($results2 as $result) { $result->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_INVALID; $result->update(); } $_MIDCOM->auth->drop_sudo(); debug_pop(); }
/** * 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_index($handler_id, $args, &$data) { $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']; $this->_request_data['sort_order'] = $this->_config->get('sort_order'); if (isset($_POST) && isset($_POST['action_type']) && ($_POST['action_type'] == 'reset_password' || $_POST['action_type'] == 'registration')) { $_MIDCOM->auth->request_sudo('fi.kilonkipinat.accountregistration'); if ($_POST['action_type'] == 'reset_password') { if (trim($_POST['username']) == '') { $error_msg = 'Täytä käyttäjätunnus-kenttä'; } else { $qb = fi_kilonkipinat_account_person_dba::new_query_builder(); $qb->add_constraint('username', '=', trim($_POST['username'])); $qb->set_limit(1); $user = $qb->execute(); if (isset($user) && count($user) > 0) { $reset_request = new fi_kilonkipinat_accountregistration_resetrequest_dba(); $reset_request->username = $user[0]->username; $reset_request->person = $user[0]->id; $reset_request->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_PASSWORDRESETREQUEST_STATUS_NEW; $reset_request->create(); $reset_request_quid = $reset_request->guid; $subject = sprintf('Salasanan vaihto palvelimella %s', $_SERVER['SERVER_NAME']); $body = sprintf('Hei %s', $user[0]->firstname); $body .= "\n\n"; $body .= sprintf($this->_l10n_midcom->get('Pyysit salasanasi resetointia palvelimella %s'), $_SERVER['SERVER_NAME']); $body .= "\n\n"; $body .= sprintf($this->_l10n_midcom->get('Resetoidaksesi salasanasi käyttäjätunnukselle %s, klikkaa alla olevaa linkkiä'), $user[0]->username); $body .= "\n\n"; $body .= 'http://' . $_SERVER['SERVER_NAME'] . $prefix . 'approve_reset/' . $reset_request_quid . '/'; $mail = new org_openpsa_mail(); $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>'; $mail->to = $user[0]->firstname . ' ' . $user[0]->lastname . ' <' . $user[0]->email . '>'; $mail->body = $body; $mail->subject = $subject; if ($mail->send('mail')) { $success_msg = $this->_l10n_midcom->get("Salasanan resetointipyyntö vastaanotettu, katso sähköpostiasi."); } } } } elseif ($_POST['action_type'] == 'registration') { if ($_POST['firstname'] == '' || $_POST['lastname'] == '' || $_POST['email'] == '') { $error_msg = 'Täytä kaikki pakolliset kentät'; } else { $accountrequest = new fi_kilonkipinat_accountregistration_accountrequest_dba(); $accountrequest->firstname = $_POST['firstname']; $accountrequest->lastname = $_POST['lastname']; $accountrequest->email = $_POST['email']; $accountrequest->status = FI_KILONKIPINAT_ACCOUNTREGISTRATION_ACCOUNT_STATUS_NEW; $accountrequest->create(); $accountrequest_quid = $accountrequest->guid; $subject = sprintf('Käyttäjätunnuksen rekisteröinti palvelimelle %s', $_SERVER['SERVER_NAME']); $body = sprintf('Hei %s', $accountrequest->firstname); $body .= "\n\n"; $body .= sprintf($this->_l10n_midcom->get('Käyttäjätunnuksen rekisteröinti palvelimelle %s.'), $_SERVER['SERVER_NAME']); $body .= "\n\n"; $body .= $this->_l10n_midcom->get('Varmistaaksesi sähköpostisi, klikkaa alla olevaa linkkiä'); $body .= "\n\n"; $body .= 'http://' . $_SERVER['SERVER_NAME'] . $prefix . 'validate_email/' . $accountrequest_quid . '/'; $mail = new org_openpsa_mail(); $mail->from = $this->_config->get('mail_sender_title') . ' <' . $this->_config->get('mail_sender_address') . '>'; $mail->to = $accountrequest->firstname . ' ' . $accountrequest->lastname . ' <' . $accountrequest->email . '>'; $mail->body = $body; $mail->subject = $subject; if ($mail->send('mail')) { $success_msg = 'Käyttäjätunnuksen rekisteröinti vastaanotettu, katso sähköpostisi'; } } } $_MIDCOM->auth->drop_sudo('fi.kilonkipinat.accountregistration'); } $message = array(); if (isset($success_msg) && $success_msg != '') { $message['title'] = 'Onnistui'; $message['content'] = $success_msg; $this->_request_data['message'] = $message; } if (isset($error_msg) && $error_msg != '') { $message['title'] = 'Virhe'; $message['content'] = $error_msg; $this->_request_data['message'] = $message; } return true; }