Try to fix password field, cache ajax_pastes output for awhile.

This commit is contained in:
Floorb 2022-04-18 13:34:00 -04:00
parent 26d00ce7b6
commit 3d11577eed
4 changed files with 15 additions and 3 deletions

View file

@ -4,6 +4,12 @@ require_once('../includes/common.php');
use PonePaste\Models\Paste; use PonePaste\Models\Paste;
if (empty($_GET['q']) && $redis->exists('ajax_pastes')) {
header('Content-Type: application/json; charset=UTF-8');
echo $redis->get('ajax_pastes');
die;
}
$pastes = Paste::with([ $pastes = Paste::with([
'user' => function($query) { 'user' => function($query) {
$query->select('users.id', 'username'); $query->select('users.id', 'username');
@ -24,7 +30,7 @@ $pastes = $pastes->get();
header('Content-Type: application/json; charset=UTF-8'); header('Content-Type: application/json; charset=UTF-8');
echo json_encode(['data' => $pastes->map(function($paste) { $pastes_json = json_encode(['data' => $pastes->map(function($paste) {
return [ return [
'id' => $paste->id, 'id' => $paste->id,
'title' => $paste->title, 'title' => $paste->title,
@ -34,3 +40,7 @@ echo json_encode(['data' => $pastes->map(function($paste) {
}) })
]; ];
})]); })]);
$redis->setEx('ajax_pastes', 3600, $pastes_json);
echo $pastes_json;

View file

@ -140,6 +140,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
]); ]);
$paste->replaceTags(Tag::parseTagInput($tag_input)); $paste->replaceTags(Tag::parseTagInput($tag_input));
$redis->del('ajax_pastes'); /* Expire from Redis so the edited paste shows up */
} else { } else {
$error = 'You must be logged in to do that.'; $error = 'You must be logged in to do that.';
} }
@ -167,6 +168,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($p_visible == '0') { if ($p_visible == '0') {
addToSitemap($paste, $priority, $changefreq); addToSitemap($paste, $priority, $changefreq);
} }
$redis->del('ajax_pastes'); /* Expire from Redis so the new paste shows up */
} }
// Redirect to paste on successful entry, or on successful edit redirect back to edited paste // Redirect to paste on successful entry, or on successful edit redirect back to edited paste

View file

@ -269,7 +269,7 @@
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<input type="text" class="input" name="pass" id="pass" <input type="text" class="input" name="pass" id="pass"
placeholder="Password" autocomplete="off" placeholder="Password" autocomplete="new-password"
value="<?php echo (isset($_POST['pass'])) ? pp_html_escape($_POST['pass']) : ''; ?>"/> value="<?php echo (isset($_POST['pass'])) ? pp_html_escape($_POST['pass']) : ''; ?>"/>
</div> </div>
</div> </div>

View file

@ -341,7 +341,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<input type="text" class="input" name="pass" id="pass" value="" <input type="text" class="input" name="pass" id="pass" value=""
placeholder="Password" autocomplete="off" /> placeholder="Password" autocomplete="new-password" />
</div> </div>
</div> </div>
</div> </div>