Multiuser system initiated with log recording

This commit is contained in:
2026-05-27 14:27:31 +08:00
parent 2b4bb5ea64
commit 1c2a0647cb
9 changed files with 619 additions and 11 deletions
+239
View File
@@ -154,6 +154,97 @@
color: var(--accent);
}
.profile-panel {
margin-top: 24px;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent),
var(--bg-elevated);
border: 1px solid var(--border);
border-radius: 8px;
padding: 18px;
box-shadow: 0 16px 34px var(--shadow);
}
.profile-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 16px;
}
.profile-title {
font-family: 'IBM Plex Mono', Consolas, monospace;
color: var(--text-muted);
font-size: 0.78rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.profile-grid {
display: grid;
grid-template-columns: repeat(5, minmax(120px, 1fr));
gap: 12px;
}
.profile-item {
border: 1px solid var(--border);
border-radius: 8px;
background: var(--panel-soft);
padding: 12px;
min-width: 0;
}
.profile-item label {
display: block;
margin-bottom: 6px;
color: var(--text-muted);
font-size: 0.72rem;
font-weight: 700;
text-transform: uppercase;
}
.profile-value {
color: var(--text-main);
font-weight: 700;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.profile-item select {
width: 100%;
background: var(--panel-soft);
border: none;
color: var(--text-main);
font: inherit;
font-weight: 700;
outline: none;
}
.profile-item select option {
background: var(--bg-card);
color: var(--text-main);
}
.profile-action {
border: 1px solid var(--border);
background: var(--panel-soft);
color: var(--text-main);
border-radius: 8px;
height: 34px;
padding: 0 13px;
cursor: pointer;
font-family: inherit;
font-weight: 700;
}
.profile-action:hover {
border-color: var(--accent);
color: var(--accent);
}
.section-title {
font-family: 'IBM Plex Mono', Consolas, monospace;
font-size: 0.78rem;
@@ -456,6 +547,15 @@
grid-template-columns: 1fr;
}
.profile-header {
align-items: flex-start;
flex-direction: column;
}
.profile-grid {
grid-template-columns: 1fr;
}
.project-card {
align-items: flex-start;
grid-template-columns: 30px minmax(0, 1fr) auto;
@@ -486,6 +586,35 @@
<div class="container">
<h2>Welcome back, <strong>{{ username }}</strong>!</h2>
<section class="profile-panel">
<div class="profile-header">
<div class="profile-title">Account Profile</div>
<button class="profile-action" type="button" id="open-password-modal">Change Password</button>
</div>
<div class="profile-grid">
<div class="profile-item">
<label>User ID</label>
<div class="profile-value" id="profile-id">-</div>
</div>
<div class="profile-item">
<label>Account Name</label>
<div class="profile-value" id="profile-username">{{ username }}</div>
</div>
<div class="profile-item">
<label>Registration Date</label>
<div class="profile-value" id="profile-created">-</div>
</div>
<div class="profile-item">
<label>Credits</label>
<div class="profile-value" id="profile-credits">0</div>
</div>
<div class="profile-item">
<label>Occupation</label>
<select id="profile-occupation"></select>
</div>
</div>
</section>
<div class="section-title">Your Projects</div>
<ul class="project-list" id="project-list">
<li class="project-card">Loading projects...</li>
@@ -524,6 +653,28 @@
</div>
</div>
<div class="modal-backdrop" id="password-modal">
<div class="modal-panel">
<h3>Change Password</h3>
<div class="modal-field">
<label for="current-password-input">Current Password</label>
<input id="current-password-input" type="password" autocomplete="current-password" />
</div>
<div class="modal-field">
<label for="new-password-input">New Password</label>
<input id="new-password-input" type="password" autocomplete="new-password" />
</div>
<div class="modal-field">
<label for="confirm-password-input">Confirm New Password</label>
<input id="confirm-password-input" type="password" autocomplete="new-password" />
</div>
<div class="modal-actions">
<button class="secondary-btn" type="button" id="cancel-password">Cancel</button>
<button class="new-project-btn" type="button" id="save-password">Update Password</button>
</div>
</div>
</div>
<script>
const projectList = document.getElementById('project-list');
const newProjectForm = document.getElementById('new-project-form');
@@ -532,6 +683,18 @@
const projectNameInput = document.getElementById('project-name-input');
const createProjectButton = document.getElementById('create-project');
const cancelProjectButton = document.getElementById('cancel-project');
const passwordModal = document.getElementById('password-modal');
const openPasswordModalButton = document.getElementById('open-password-modal');
const cancelPasswordButton = document.getElementById('cancel-password');
const savePasswordButton = document.getElementById('save-password');
const currentPasswordInput = document.getElementById('current-password-input');
const newPasswordInput = document.getElementById('new-password-input');
const confirmPasswordInput = document.getElementById('confirm-password-input');
const profileId = document.getElementById('profile-id');
const profileUsername = document.getElementById('profile-username');
const profileCreated = document.getElementById('profile-created');
const profileCredits = document.getElementById('profile-credits');
const profileOccupation = document.getElementById('profile-occupation');
const themeToggle = document.getElementById('theme-toggle');
const logTerminal = document.getElementById('log-terminal');
let technologies = [];
@@ -558,6 +721,81 @@
window.location.href = `/canvas?project=${encodeURIComponent(name)}`;
}
async function loadProfile() {
try {
const response = await fetch('/api/profile');
const profile = await response.json();
if (!response.ok) {
addLog(profile.error || 'Failed to load profile.');
return;
}
profileId.textContent = profile.id;
profileUsername.textContent = profile.username;
profileCreated.textContent = profile.created_at || '-';
profileCredits.textContent = profile.credits ?? 0;
profileOccupation.innerHTML = '';
(profile.occupations || []).forEach(occupation => {
const option = document.createElement('option');
option.value = occupation;
option.textContent = occupation;
option.selected = occupation === profile.occupation;
profileOccupation.appendChild(option);
});
} catch (error) {
addLog('Failed to load profile.');
}
}
profileOccupation.addEventListener('change', async () => {
const response = await fetch('/api/profile', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ occupation: profileOccupation.value })
});
const result = await response.json();
if (!response.ok) {
addLog(result.error || 'Failed to update occupation.');
loadProfile();
return;
}
addLog(`Updated occupation to "${result.occupation}".`);
});
openPasswordModalButton.addEventListener('click', () => {
currentPasswordInput.value = '';
newPasswordInput.value = '';
confirmPasswordInput.value = '';
passwordModal.classList.add('open');
currentPasswordInput.focus();
});
cancelPasswordButton.addEventListener('click', () => {
passwordModal.classList.remove('open');
});
savePasswordButton.addEventListener('click', async () => {
const newPassword = newPasswordInput.value;
if (newPassword !== confirmPasswordInput.value) {
addLog('Password update failed: confirmation does not match.');
return;
}
const response = await fetch('/api/profile/password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
current_password: currentPasswordInput.value,
new_password: newPassword
})
});
const result = await response.json();
if (!response.ok) {
addLog(result.error || 'Password update failed.');
return;
}
passwordModal.classList.remove('open');
addLog('Password updated.');
});
async function loadProjects() {
try {
const response = await fetch('/api/projects');
@@ -658,6 +896,7 @@
}
loadTechnologies();
loadProfile();
loadProjects();
</script>
</body>