diff --git a/.vscode/settings.json b/.vscode/settings.json index f673a71..155422b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "liveServer.settings.port": 5502 + "liveServer.settings.port": 5503 } \ No newline at end of file diff --git a/firebase.js b/firebase.js new file mode 100644 index 0000000..5211140 --- /dev/null +++ b/firebase.js @@ -0,0 +1,16 @@ +import { initializeApp } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-app.js"; +import { getFirestore } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-firestore.js"; + +const firebaseConfig = { + apiKey: "SUA_API_KEY", + authDomain: "SEU_PROJETO.firebaseapp.com", + projectId: "SEU_PROJECT_ID", + storageBucket: "SEU_PROJETO.appspot.com", + messagingSenderId: "SEU_ID", + appId: "SEU_APP_ID" +}; + +const app = initializeApp(firebaseConfig); +const db = getFirestore(app); + +export { db }; \ No newline at end of file diff --git a/index.html b/index.html index 2d085bc..4485476 100644 --- a/index.html +++ b/index.html @@ -95,10 +95,10 @@ Building2, Users, Wallet, Wrench, Bell, Search, Plus, Menu, X, TrendingUp, TrendingDown, CheckCircle, AlertCircle, Clock, LogOut, Edit2, Trash2, Save, Filter, MoreVertical, FileText, - Dumbbell, PartyPopper, Trophy, Map, Calendar, MapPin, Info + Dumbbell, PartyPopper, Trophy, Map, Calendar, MapPin, Info, + MessageCircle, Paperclip, Send } from 'lucide-react'; - const INITIAL_RESIDENTS = [ { id: 1, unit: '1º Esq', name: 'Ana Silva', contact: '912 345 678', email: 'ana.silva@email.com', status: 'Pago', pending: 0, role: 'morador' }, { id: 2, unit: '1º Dto', name: 'Carlos Santos', contact: '965 432 109', email: 'carlos.s@email.com', status: 'Pendente', pending: 45.00, role: 'morador' }, @@ -256,9 +256,9 @@ const [password, setPassword] = useState(''); const [error, setError] = useState(''); - const handleSubmit = (e) => { + const handleSubmit = async (e) => { e.preventDefault(); - const success = onLogin(email, password); + const success = await onLogin(email, password); if (!success) { setError('Email ou Palavra-passe incorreta'); } @@ -327,27 +327,46 @@ return sessionStorage.getItem('condo_role') || 'morador'; }); - const handleLogin = (email, password) => { - let role = null; - if (email === 'administradores@gmail.com' && password === 'admin123') { - role = 'admin'; - } else if (email === 'moradores@gmail.com' && password === 'moradores123') { - role = 'morador'; - } else { - const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase()); - if (residentUser && (password === residentUser.contact || password === '1234')) { - role = residentUser.role || 'morador'; + const handleLogin = async (email, password) => { + try { + const userCredential = await signInWithEmailAndPassword(auth, email, password); + let role = 'morador'; + if (email.toLowerCase().includes('admin')) { + role = 'admin'; + } else { + const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase()); + if (residentUser) { + role = residentUser.role || 'morador'; + } } - } - - if (role) { sessionStorage.setItem('condo_auth', 'true'); sessionStorage.setItem('condo_role', role); setIsAuthenticated(true); setUserRole(role); return true; + } catch (error) { + console.log("Firebase Auth falhou, a tentar conta local...", error); + let role = null; + if (email === 'administradores@gmail.com' && password === 'admin123') { + role = 'admin'; + } else if (email === 'moradores@gmail.com' && password === 'moradores123') { + role = 'morador'; + } else { + const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase()); + if (residentUser && (password === residentUser.contact || password === '1234')) { + role = residentUser.role || 'morador'; + } + } + + if (role) { + sessionStorage.setItem('condo_auth', 'true'); + sessionStorage.setItem('condo_role', role); + setIsAuthenticated(true); + setUserRole(role); + return true; + } + return false; } - return false; }; const handleLogout = () => { @@ -1629,23 +1648,7 @@ const root = createRoot(document.getElementById('root')); root.render(); - + \ No newline at end of file diff --git a/script.js b/script.js index f37d721..23cec1d 100644 --- a/script.js +++ b/script.js @@ -490,3 +490,5 @@ function exportPDF(tableId, filename) { doc.save(filename + '.pdf'); showToast("PDF gerado com sucesso!", "success"); } +import { db } from "./firebase.js"; +import { collection, addDoc } from "https://www.gstatic.com/firebasejs/12.1.0/firebase-firestore.js";