Add user self-registration and implement rate limiting for predictions
Allow users to add themselves to the player database through a web form, eliminating the need for manual pdga-numbers.txt updates. Implement 24-hour rate limiting on prediction refreshes to prevent abuse while maintaining reasonable update frequency. Key changes: - Add player self-registration with PDGA number lookup and confirmation - Store predicted ratings in database for persistence across restarts - Implement 24-hour rate limit on prediction refresh endpoint - Make database the single source of truth (text file only for initial seed) - Remove "Scrape All Layouts" bulk operation button - Update "Load All" to refresh existing players instead of text file 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+69
-41
@@ -87,6 +87,29 @@
|
||||
background-color: #6c757d;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.search-container {
|
||||
margin-bottom: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.search-input {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
padding: 10px 15px;
|
||||
font-size: 16px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 4px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
.search-input:focus {
|
||||
border-color: #007bff;
|
||||
}
|
||||
.search-results-info {
|
||||
text-align: center;
|
||||
margin: 10px 0;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
@@ -251,13 +274,21 @@
|
||||
<a href="/courses.html" style="color: #333;">Courses</a>
|
||||
</div>
|
||||
|
||||
<div class="search-container">
|
||||
<input
|
||||
type="text"
|
||||
class="search-input"
|
||||
id="course-search"
|
||||
placeholder="Search courses by name or city..."
|
||||
oninput="searchCourses()"
|
||||
/>
|
||||
</div>
|
||||
<div id="search-results-info" class="search-results-info"></div>
|
||||
|
||||
<div class="controls">
|
||||
<button class="btn" onclick="scrapeCourses()" id="scrape-courses-btn">
|
||||
<i class="fas fa-sync-alt"></i> Scrape Courses
|
||||
</button>
|
||||
<button class="btn" onclick="scrapeAllLayouts()" id="scrape-all-layouts-btn">
|
||||
<i class="fas fa-layer-group"></i> Scrape All Layouts
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="loading" class="loading" style="display: none;">Loading courses...</div>
|
||||
@@ -265,6 +296,8 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let allCourses = [];
|
||||
|
||||
async function loadCourses() {
|
||||
const loading = document.getElementById('loading');
|
||||
const tableDiv = document.getElementById('courses-table');
|
||||
@@ -274,10 +307,11 @@
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/courses');
|
||||
const courses = await response.json();
|
||||
allCourses = await response.json();
|
||||
|
||||
loading.style.display = 'none';
|
||||
displayCourses(courses);
|
||||
displayCourses(allCourses);
|
||||
updateSearchInfo(allCourses.length, allCourses.length);
|
||||
} catch (error) {
|
||||
console.error('Error loading courses:', error);
|
||||
loading.style.display = 'none';
|
||||
@@ -285,6 +319,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
function searchCourses() {
|
||||
const searchInput = document.getElementById('course-search');
|
||||
const searchTerm = searchInput.value.toLowerCase().trim();
|
||||
|
||||
if (!searchTerm) {
|
||||
displayCourses(allCourses);
|
||||
updateSearchInfo(allCourses.length, allCourses.length);
|
||||
return;
|
||||
}
|
||||
|
||||
const filtered = allCourses.filter(course => {
|
||||
return course.name.toLowerCase().includes(searchTerm) ||
|
||||
course.city.toLowerCase().includes(searchTerm);
|
||||
});
|
||||
|
||||
displayCourses(filtered);
|
||||
updateSearchInfo(filtered.length, allCourses.length);
|
||||
}
|
||||
|
||||
function updateSearchInfo(showing, total) {
|
||||
const infoDiv = document.getElementById('search-results-info');
|
||||
if (showing === total) {
|
||||
infoDiv.textContent = `Showing all ${total} courses`;
|
||||
} else {
|
||||
infoDiv.textContent = `Showing ${showing} of ${total} courses`;
|
||||
}
|
||||
}
|
||||
|
||||
function displayCourses(courses) {
|
||||
const tableDiv = document.getElementById('courses-table');
|
||||
|
||||
@@ -490,7 +552,8 @@
|
||||
|
||||
if (data.success) {
|
||||
alert(data.message);
|
||||
loadCourses(); // Reload the courses list
|
||||
await loadCourses(); // Reload the courses list
|
||||
searchCourses(); // Reapply search filter if any
|
||||
} else {
|
||||
alert('Failed to scrape courses');
|
||||
}
|
||||
@@ -542,41 +605,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function scrapeAllLayouts() {
|
||||
const btn = document.getElementById('scrape-all-layouts-btn');
|
||||
|
||||
if (!confirm('This will scrape layouts for all courses. This may take several minutes. Continue?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-sync-alt spinning"></i> Scraping...';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/scrape-all-layouts', {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
alert(data.message);
|
||||
// Clear all loaded states to force reload
|
||||
document.querySelectorAll('.layouts-container').forEach(container => {
|
||||
container.dataset.loaded = 'false';
|
||||
});
|
||||
} else {
|
||||
alert('Failed to scrape layouts');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error scraping all layouts:', error);
|
||||
alert('Error scraping all layouts');
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-layer-group"></i> Scrape All Layouts';
|
||||
}
|
||||
}
|
||||
|
||||
// Load courses on page load
|
||||
loadCourses();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user