fix: include auth.js in dashboard overhaul
This commit is contained in:
@@ -55,42 +55,33 @@ class AuthManager {
|
|||||||
const loginBtn = document.querySelector('.login-btn');
|
const loginBtn = document.querySelector('.login-btn');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Show loading state
|
|
||||||
loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Authenticating...';
|
loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Authenticating...';
|
||||||
loginBtn.disabled = true;
|
loginBtn.disabled = true;
|
||||||
|
|
||||||
// Simple authentication - in production, this would call an API
|
const response = await fetch('/api/auth/login', {
|
||||||
// For now, using mock authentication
|
method: 'POST',
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username, password })
|
||||||
|
});
|
||||||
|
|
||||||
if (username === 'admin' && password === 'admin123') {
|
const result = await response.json();
|
||||||
// Successful login
|
|
||||||
this.token = this.generateToken();
|
if (result.success) {
|
||||||
this.user = {
|
this.token = result.data.token;
|
||||||
username: 'admin',
|
this.user = result.data.user;
|
||||||
name: 'Administrator',
|
|
||||||
role: 'Super Admin',
|
|
||||||
avatar: null
|
|
||||||
};
|
|
||||||
|
|
||||||
// Save to localStorage
|
|
||||||
localStorage.setItem('dashboard_token', this.token);
|
localStorage.setItem('dashboard_token', this.token);
|
||||||
localStorage.setItem('dashboard_user', JSON.stringify(this.user));
|
localStorage.setItem('dashboard_user', JSON.stringify(this.user));
|
||||||
|
|
||||||
this.isAuthenticated = true;
|
this.isAuthenticated = true;
|
||||||
this.showDashboard();
|
this.showDashboard();
|
||||||
|
|
||||||
// Show success message
|
|
||||||
this.showToast('Successfully logged in!', 'success');
|
this.showToast('Successfully logged in!', 'success');
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid credentials');
|
throw new Error(result.error || 'Invalid credentials');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Show error
|
|
||||||
errorElement.style.display = 'flex';
|
errorElement.style.display = 'flex';
|
||||||
errorElement.querySelector('span').textContent = error.message;
|
errorElement.querySelector('span').textContent = error.message;
|
||||||
|
|
||||||
// Reset button
|
|
||||||
loginBtn.innerHTML = '<i class="fas fa-sign-in-alt"></i> Sign In';
|
loginBtn.innerHTML = '<i class="fas fa-sign-in-alt"></i> Sign In';
|
||||||
loginBtn.disabled = false;
|
loginBtn.disabled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user