Merge immortal/main into audit/securite-maintenabilite-standards
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block title %}{{ _('Register') }} - TryoutPro{% endblock %}
|
||||
{% block title %}{{ _('Register') }} - UdeS team manager{% endblock %}
|
||||
{% block auth_content %}
|
||||
<form method="POST" action="{{ url_for('auth.register') }}" class="auth-form">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
@@ -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" data-action="save-form-draft">
|
||||
<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" data-action="save-form-draft">
|
||||
<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>
|
||||
@@ -170,8 +170,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.indexOf('password') !== -1) {
|
||||
// Skip CSRF token 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);
|
||||
@@ -182,6 +236,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// dispatched by the delegated listener in main.js. This replaces inline
|
||||
// onclick attributes, which no CSP nonce is able to authorise.
|
||||
registerActions({
|
||||
'save-form-draft': saveFormDraft,
|
||||
'toggle-gamertag': toggleGamertagInput,
|
||||
});
|
||||
</script>
|
||||
@@ -301,4 +356,4 @@ registerActions({
|
||||
color: #57F287 !important;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user