Ligação inicial ao Firebase e criação do formulário de condomínios
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"liveServer.settings.port": 5502
|
"liveServer.settings.port": 5503
|
||||||
}
|
}
|
||||||
16
firebase.js
Normal file
16
firebase.js
Normal file
@@ -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 };
|
||||||
73
index.html
73
index.html
@@ -95,10 +95,10 @@
|
|||||||
Building2, Users, Wallet, Wrench, Bell, Search, Plus, Menu, X,
|
Building2, Users, Wallet, Wrench, Bell, Search, Plus, Menu, X,
|
||||||
TrendingUp, TrendingDown, CheckCircle, AlertCircle, Clock, LogOut,
|
TrendingUp, TrendingDown, CheckCircle, AlertCircle, Clock, LogOut,
|
||||||
Edit2, Trash2, Save, Filter, MoreVertical, FileText,
|
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';
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
|
||||||
const INITIAL_RESIDENTS = [
|
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: 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' },
|
{ 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 [password, setPassword] = useState('');
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const success = onLogin(email, password);
|
const success = await onLogin(email, password);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
setError('Email ou Palavra-passe incorreta');
|
setError('Email ou Palavra-passe incorreta');
|
||||||
}
|
}
|
||||||
@@ -327,27 +327,46 @@
|
|||||||
return sessionStorage.getItem('condo_role') || 'morador';
|
return sessionStorage.getItem('condo_role') || 'morador';
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleLogin = (email, password) => {
|
const handleLogin = async (email, password) => {
|
||||||
let role = null;
|
try {
|
||||||
if (email === 'administradores@gmail.com' && password === 'admin123') {
|
const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
||||||
role = 'admin';
|
let role = 'morador';
|
||||||
} else if (email === 'moradores@gmail.com' && password === 'moradores123') {
|
if (email.toLowerCase().includes('admin')) {
|
||||||
role = 'morador';
|
role = 'admin';
|
||||||
} else {
|
} else {
|
||||||
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
|
const residentUser = residents.find(r => r.email && r.email.toLowerCase() === email.toLowerCase());
|
||||||
if (residentUser && (password === residentUser.contact || password === '1234')) {
|
if (residentUser) {
|
||||||
role = residentUser.role || 'morador';
|
role = residentUser.role || 'morador';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (role) {
|
|
||||||
sessionStorage.setItem('condo_auth', 'true');
|
sessionStorage.setItem('condo_auth', 'true');
|
||||||
sessionStorage.setItem('condo_role', role);
|
sessionStorage.setItem('condo_role', role);
|
||||||
setIsAuthenticated(true);
|
setIsAuthenticated(true);
|
||||||
setUserRole(role);
|
setUserRole(role);
|
||||||
return true;
|
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 = () => {
|
const handleLogout = () => {
|
||||||
@@ -1629,23 +1648,7 @@
|
|||||||
const root = createRoot(document.getElementById('root'));
|
const root = createRoot(document.getElementById('root'));
|
||||||
root.render(<App />);
|
root.render(<App />);
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
<!-- Firebase configs moved to top in React Module -->
|
||||||
import { initializeApp } from "https://www.gstatic.com/firebasejs/12.10.0/firebase-app.js";
|
|
||||||
import { getAnalytics } from "https://www.gstatic.com/firebasejs/12.10.0/firebase-analytics.js";
|
|
||||||
|
|
||||||
const firebaseConfig = {
|
|
||||||
apiKey: "AIzaSyAQHgVDJWM42HfRzvKTxdVW78Qq48vBb2A",
|
|
||||||
authDomain: "condomaster-pro-ed9af.firebaseapp.com",
|
|
||||||
projectId: "condomaster-pro-ed9af",
|
|
||||||
storageBucket: "condomaster-pro-ed9af.firebasestorage.app",
|
|
||||||
messagingSenderId: "169472241616",
|
|
||||||
appId: "1:169472241616:web:8e6074dc4b8a6dce9013d5",
|
|
||||||
measurementId: "G-2BH2VTW6D5"
|
|
||||||
};
|
|
||||||
|
|
||||||
const app = initializeApp(firebaseConfig);
|
|
||||||
const analytics = getAnalytics(app);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -490,3 +490,5 @@ function exportPDF(tableId, filename) {
|
|||||||
doc.save(filename + '.pdf');
|
doc.save(filename + '.pdf');
|
||||||
showToast("PDF gerado com sucesso!", "success");
|
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";
|
||||||
|
|||||||
Reference in New Issue
Block a user