Spaces:
Running
Running
Upload 10 files
Browse files- src/views/InstructorView.js +43 -0
src/views/InstructorView.js
CHANGED
|
@@ -376,6 +376,49 @@ export async function renderInstructorView() {
|
|
| 376 |
export function setupInstructorEvents() {
|
| 377 |
console.log("Starting setupInstructorEvents...");
|
| 378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
// --- Instructor Management Helper ---
|
| 380 |
async function loadInstructorList() {
|
| 381 |
const tbody = document.getElementById('instructor-list-body');
|
|
|
|
| 376 |
export function setupInstructorEvents() {
|
| 377 |
console.log("Starting setupInstructorEvents...");
|
| 378 |
|
| 379 |
+
// Login Logic
|
| 380 |
+
const loginBtn = document.getElementById('login-btn');
|
| 381 |
+
const registerBtn = document.getElementById('register-btn');
|
| 382 |
+
const emailInput = document.getElementById('login-email');
|
| 383 |
+
const passwordInput = document.getElementById('login-password');
|
| 384 |
+
const authErrorMsg = document.getElementById('auth-error');
|
| 385 |
+
|
| 386 |
+
if (loginBtn) {
|
| 387 |
+
loginBtn.addEventListener('click', async () => {
|
| 388 |
+
const email = emailInput.value.trim();
|
| 389 |
+
const password = passwordInput.value.trim();
|
| 390 |
+
if (!email || !password) return alert("請輸入帳號與密碼");
|
| 391 |
+
|
| 392 |
+
try {
|
| 393 |
+
// Determine if this is a login or register flow?
|
| 394 |
+
// Wait, register btn is separate.
|
| 395 |
+
await loginWithEmail(email, password);
|
| 396 |
+
// Auth Observer will handle the rest
|
| 397 |
+
} catch (e) {
|
| 398 |
+
console.error("Login Error:", e);
|
| 399 |
+
authErrorMsg.textContent = "登入失敗: " + e.message;
|
| 400 |
+
authErrorMsg.classList.remove('hidden');
|
| 401 |
+
}
|
| 402 |
+
});
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
if (registerBtn) {
|
| 406 |
+
registerBtn.addEventListener('click', async () => {
|
| 407 |
+
const email = emailInput.value.trim();
|
| 408 |
+
const password = passwordInput.value.trim();
|
| 409 |
+
if (!email || !password) return alert("請輸入帳號與密碼");
|
| 410 |
+
|
| 411 |
+
try {
|
| 412 |
+
await registerWithEmail(email, password);
|
| 413 |
+
alert("註冊成功,請登入");
|
| 414 |
+
} catch (e) {
|
| 415 |
+
console.error("Register Error:", e);
|
| 416 |
+
authErrorMsg.textContent = "註冊失敗: " + e.message;
|
| 417 |
+
authErrorMsg.classList.remove('hidden');
|
| 418 |
+
}
|
| 419 |
+
});
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
// --- Instructor Management Helper ---
|
| 423 |
async function loadInstructorList() {
|
| 424 |
const tbody = document.getElementById('instructor-list-body');
|