191 lines
8.4 KiB
HTML
191 lines
8.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>C Programming Learning System</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<link rel="stylesheet" href="{{ url_for('send_static', path='style.css') }}">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="/">
|
|
<i class="fas fa-code"></i> C Programming Learning System
|
|
</a>
|
|
<div class="d-flex">
|
|
<form class="d-flex" id="token-form" style="display: flex; align-items: center;">
|
|
<input class="form-control me-2" type="text" id="student-token" placeholder="Enter token" style="width: 200px;">
|
|
<button class="btn btn-outline-light" type="submit">Login</button>
|
|
</form>
|
|
<div id="student-info" class="text-light" style="margin-left: 15px; display: none;"></div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<h1 class="mb-4">C Programming Learning System</h1>
|
|
|
|
<!-- Home content rendered from markdown -->
|
|
<div class="home-content mb-5">
|
|
{{ home_content | safe }}
|
|
</div>
|
|
|
|
<h2 class="mb-4">Available Lessons</h2>
|
|
|
|
{% if lessons %}
|
|
<div class="row">
|
|
{% for lesson in lessons %}
|
|
<div class="col-md-6 col-lg-4 mb-4">
|
|
<div class="card h-100 lesson-card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">{{ lesson.title }}</h5>
|
|
<p class="card-text">{{ lesson.description }}</p>
|
|
</div>
|
|
<div class="card-footer">
|
|
<a href="{{ url_for('lesson', filename=lesson.filename) }}" class="btn btn-primary">Start Learning</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% else %}
|
|
<div class="alert alert-info">
|
|
<h4>No lessons available</h4>
|
|
<p>Add markdown files to the content directory to create lessons.</p>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="footer mt-5 py-4 bg-light">
|
|
<div class="container text-center">
|
|
<span class="text-muted">C Programming Learning System © 2025</span>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const tokenForm = document.getElementById('token-form');
|
|
const studentTokenInput = document.getElementById('student-token');
|
|
const studentInfoDiv = document.getElementById('student-info');
|
|
|
|
// Handle token form submission
|
|
tokenForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const token = studentTokenInput.value.trim();
|
|
|
|
if (!token) {
|
|
alert('Please enter a token');
|
|
return;
|
|
}
|
|
|
|
// Send token to server for validation
|
|
fetch('/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ token: token })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Store token in localStorage for persistence
|
|
localStorage.setItem('student_token', token);
|
|
|
|
// Update UI to show student info
|
|
studentInfoDiv.textContent = `Welcome, ${data.student_name}!`;
|
|
studentInfoDiv.style.display = 'block';
|
|
|
|
// Hide the form after successful login
|
|
tokenForm.style.display = 'none';
|
|
|
|
// Update the token input to show logged in state
|
|
studentTokenInput.placeholder = 'Logged in';
|
|
studentTokenInput.disabled = true;
|
|
|
|
// Add logout button
|
|
const logoutBtn = document.createElement('button');
|
|
logoutBtn.className = 'btn btn-outline-light';
|
|
logoutBtn.textContent = 'Logout';
|
|
logoutBtn.type = 'button';
|
|
logoutBtn.onclick = function() {
|
|
localStorage.removeItem('student_token');
|
|
// Clear the token input field
|
|
const tokenInput = document.getElementById('student-token');
|
|
if (tokenInput) {
|
|
tokenInput.value = '';
|
|
tokenInput.placeholder = 'Enter token';
|
|
tokenInput.disabled = false;
|
|
}
|
|
location.reload();
|
|
};
|
|
tokenForm.appendChild(logoutBtn);
|
|
} else {
|
|
alert(data.message || 'Invalid token');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An error occurred while logging in');
|
|
});
|
|
});
|
|
|
|
// Check if user is already logged in
|
|
const savedToken = localStorage.getItem('student_token');
|
|
if (savedToken) {
|
|
// Validate the saved token
|
|
fetch('/validate-token', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ token: savedToken })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Update UI to show student info
|
|
studentInfoDiv.textContent = `Welcome, ${data.student_name}!`;
|
|
studentInfoDiv.style.display = 'block';
|
|
|
|
// Hide the form since user is already logged in
|
|
tokenForm.style.display = 'none';
|
|
|
|
// Add logout button
|
|
const logoutBtn = document.createElement('button');
|
|
logoutBtn.className = 'btn btn-outline-light';
|
|
logoutBtn.textContent = 'Logout';
|
|
logoutBtn.type = 'button';
|
|
logoutBtn.onclick = function() {
|
|
localStorage.removeItem('student_token');
|
|
// Clear the token input field
|
|
const tokenInput = document.getElementById('student-token');
|
|
if (tokenInput) {
|
|
tokenInput.value = '';
|
|
tokenInput.placeholder = 'Enter token';
|
|
tokenInput.disabled = false;
|
|
}
|
|
location.reload();
|
|
};
|
|
tokenForm.appendChild(logoutBtn);
|
|
} else {
|
|
// Token is invalid, remove it from localStorage
|
|
localStorage.removeItem('student_token');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error validating token:', error);
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |