From 4dc3ea6edab4552daf646e7b34171b1727ddbd23 Mon Sep 17 00:00:00 2001
From: wzp <2040239371@qq.com>
Date: 星期二, 07 四月 2026 16:42:28 +0800
Subject: [PATCH] fix:增加添越智
---
映星教育/snippet-5-training.php | 47 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 40 insertions(+), 7 deletions(-)
diff --git "a/\346\230\240\346\230\237\346\225\231\350\202\262/snippet-5-training.php" "b/\346\230\240\346\230\237\346\225\231\350\202\262/snippet-5-training.php"
index 97467bb..7281e69 100644
--- "a/\346\230\240\346\230\237\346\225\231\350\202\262/snippet-5-training.php"
+++ "b/\346\230\240\346\230\237\346\225\231\350\202\262/snippet-5-training.php"
@@ -19,7 +19,12 @@
============================================================ */
add_action('template_redirect', function () {
if (!empty($_GET['im_training_token'])) {
+ if (!defined('DONOTCACHEPAGE')) {
+ define('DONOTCACHEPAGE', true);
+ }
nocache_headers();
+ header('Cache-Control: private, no-store, no-cache, must-revalidate, max-age=0');
+ header('Pragma: no-cache');
}
}, 1);
@@ -98,6 +103,20 @@
.im-tr-btn-loading::after{content:"";position:absolute;width:20px;height:20px;top:50%;left:50%;margin:-10px 0 0 -10px;border:3px solid rgba(255,255,255,.3);border-top-color:#fff;border-radius:50%;animation:imTrSpin .6s linear infinite}
</style>';
echo '<script>var imTrAjaxUrl="' . esc_url(admin_url('admin-ajax.php')) . '";</script>';
+}
+
+/* ============================================================
+ AJAX: Fresh nonce (avoids stale nonce from full-page cache / long sessions)
+ ============================================================ */
+add_action('wp_ajax_im_training_refresh_nonce', 'im_ajax_training_refresh_nonce');
+add_action('wp_ajax_nopriv_im_training_refresh_nonce', 'im_ajax_training_refresh_nonce');
+function im_ajax_training_refresh_nonce()
+{
+ $token = sanitize_text_field($_POST['im_training_token'] ?? '');
+ if (!$token || !IM_Candidate::get_by_training_token($token)) {
+ wp_send_json_error(['message' => 'Invalid or expired training link.']);
+ }
+ wp_send_json_success(['nonce' => wp_create_nonce('im_training_' . $token)]);
}
/* ============================================================
@@ -193,7 +212,6 @@
endif;
$name = esc_html($candidate->preferred_name ?: $candidate->first_name);
- $nonce = wp_create_nonce('im_training_' . $token_str);
$total = count($training_posts);
// Build training data for JS
@@ -501,15 +519,30 @@
document.getElementById('im-tr-progress-text').textContent = 'Progress: ' + completed + ' / ' + TOTAL;
}
- function submitTrainingComplete() {
- var fd = new FormData();
- fd.append('action', 'im_training_complete');
- fd.append('im_training_token', '<?= esc_js($token_str) ?>');
- fd.append('im_nonce', '<?= esc_js($nonce) ?>');
+ var imTrToken = '<?= esc_js($token_str) ?>';
- fetch(imTrAjaxUrl, { method: 'POST', body: fd })
+ function submitTrainingComplete() {
+ var refresh = new FormData();
+ refresh.append('action', 'im_training_refresh_nonce');
+ refresh.append('im_training_token', imTrToken);
+
+ fetch(imTrAjaxUrl, { method: 'POST', body: refresh, credentials: 'same-origin' })
.then(function (r) { return r.json(); })
+ .then(function (nr) {
+ if (!nr.success || !nr.data || !nr.data.nonce) {
+ alert((nr.data && nr.data.message) || 'Security check failed. Please refresh the page and try again.');
+ return;
+ }
+ var fd = new FormData();
+ fd.append('action', 'im_training_complete');
+ fd.append('im_training_token', imTrToken);
+ fd.append('im_nonce', nr.data.nonce);
+
+ return fetch(imTrAjaxUrl, { method: 'POST', body: fd, credentials: 'same-origin' });
+ })
+ .then(function (r) { return r ? r.json() : null; })
.then(function (res) {
+ if (!res) return;
if (res.success) {
var page = document.getElementById('im-tr-page');
page.innerHTML = '<div class="im-tr-center im-tr-fade-in">'
--
Gitblit v1.9.1