cache local dans le register page
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<a href="{{ url_for('auth.discord_login') }}" class="btn btn-sm btn-outline discord-reconnect">
|
||||
<a href="{{ url_for('auth.discord_login') }}" class="btn btn-sm btn-outline discord-reconnect" onclick="saveFormDraft()">
|
||||
<i class="fas fa-sync-alt"></i> Reconnect
|
||||
</a>
|
||||
</div>
|
||||
@@ -65,7 +65,7 @@
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="form-group discord-connect-section">
|
||||
<a href="{{ url_for('auth.discord_login') }}" class="btn btn-discord btn-block">
|
||||
<a href="{{ url_for('auth.discord_login') }}" class="btn btn-discord btn-block" onclick="saveFormDraft()">
|
||||
<i class="fab fa-discord"></i> Connect Discord Account
|
||||
</a>
|
||||
<small class="form-text text-muted">Connect to pre-fill your gamertags from Steam, Battle.net, Xbox, etc.</small>
|
||||
@@ -165,8 +165,62 @@ function toggleGamertagInput(checkbox) {
|
||||
}
|
||||
}
|
||||
|
||||
// On page load, ensure gamertag groups match checkbox state
|
||||
// Save form draft to sessionStorage before navigating to Discord OAuth
|
||||
function saveFormDraft() {
|
||||
var draft = {};
|
||||
var form = document.querySelector('.auth-form');
|
||||
if (!form) return;
|
||||
var inputs = form.querySelectorAll('input, select, textarea');
|
||||
inputs.forEach(function(input) {
|
||||
if (!input.name) return;
|
||||
if (input.type === 'checkbox') {
|
||||
if (!draft[input.name]) draft[input.name] = [];
|
||||
if (input.checked) draft[input.name].push(input.value);
|
||||
} else if (input.type === 'password') {
|
||||
// Never save passwords
|
||||
} else {
|
||||
draft[input.name] = input.value;
|
||||
}
|
||||
});
|
||||
sessionStorage.setItem('register_form_draft', JSON.stringify(draft));
|
||||
}
|
||||
|
||||
// Restore form draft from sessionStorage on page load
|
||||
function restoreFormDraft() {
|
||||
var saved = sessionStorage.getItem('register_form_draft');
|
||||
if (!saved) return;
|
||||
try {
|
||||
var draft = JSON.parse(saved);
|
||||
var hasServerData = document.querySelector('.auth-form input[name="full_name"]').value !== '';
|
||||
if (hasServerData) return;
|
||||
for (var key in draft) {
|
||||
if (key === 'games') {
|
||||
var values = draft[key];
|
||||
var checkboxes = document.querySelectorAll('input[name="games"]');
|
||||
checkboxes.forEach(function(cb) {
|
||||
cb.checked = values.indexOf(cb.value) !== -1;
|
||||
toggleGamertagInput(cb);
|
||||
});
|
||||
} else if (key === 'csrf_token' || key === 'captcha_answer' || key.indexOf('password') !== -1) {
|
||||
// Skip CSRF token, CAPTCHA, and passwords
|
||||
} else {
|
||||
var input = document.querySelector('input[name="' + key + '"], textarea[name="' + key + '"]');
|
||||
if (input) input.value = draft[key];
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
// Invalid JSON, ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Clear draft on successful form submission
|
||||
document.querySelector('.auth-form').addEventListener('submit', function() {
|
||||
sessionStorage.removeItem('register_form_draft');
|
||||
});
|
||||
|
||||
// On page load, ensure gamertag groups match checkbox state and restore draft
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
restoreFormDraft();
|
||||
var checkboxes = document.querySelectorAll('input[name="games"]');
|
||||
checkboxes.forEach(function(checkbox) {
|
||||
toggleGamertagInput(checkbox);
|
||||
|
||||
Reference in New Issue
Block a user