Initial commit
This commit is contained in:
24
screens/AdminScreen.tsx
Normal file
24
screens/AdminScreen.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
import { View, Text, Button, StyleSheet } from 'react-native';
|
||||
import { signOut } from 'firebase/auth';
|
||||
import { auth } from '../config/firebase';
|
||||
|
||||
export default function AdminScreen({ navigation }: any) {
|
||||
const handleLogout = async () => {
|
||||
await signOut(auth);
|
||||
navigation.replace('Login');
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.title}>Admin Panel</Text>
|
||||
<Text>Csak adminok láthatják ezt a képernyőt</Text>
|
||||
<Button title="Kijelentkezés" onPress={handleLogout} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16, justifyContent: 'center', alignItems: 'center' },
|
||||
title: { fontSize: 24, fontWeight: 'bold', marginBottom: 16 },
|
||||
});
|
||||
53
screens/LoginScreen.tsx
Normal file
53
screens/LoginScreen.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, TextInput, Button, StyleSheet, Text } from 'react-native';
|
||||
import { signInWithEmailAndPassword, createUserWithEmailAndPassword } from 'firebase/auth';
|
||||
import { doc, setDoc, getDoc } from 'firebase/firestore';
|
||||
import { auth, db } from '../config/firebase';
|
||||
|
||||
export default function LoginScreen({ navigation }: any) {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [isAdmin, setIsAdmin] = useState(false);
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
||||
const userDoc = await getDoc(doc(db, 'users', userCredential.user.uid));
|
||||
const role = userDoc.data()?.role || 'user';
|
||||
navigation.replace(role === 'admin' ? 'Admin' : 'Profile');
|
||||
} catch (error: any) {
|
||||
alert(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegister = async () => {
|
||||
try {
|
||||
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
|
||||
await setDoc(doc(db, 'users', userCredential.user.uid), {
|
||||
email,
|
||||
role: isAdmin ? 'admin' : 'user',
|
||||
});
|
||||
navigation.replace(isAdmin ? 'Admin' : 'Profile');
|
||||
} catch (error: any) {
|
||||
alert(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput style={styles.input} placeholder="Email" value={email} onChangeText={setEmail} />
|
||||
<TextInput style={styles.input} placeholder="Jelszó" value={password} onChangeText={setPassword} secureTextEntry />
|
||||
<Button title="Bejelentkezés" onPress={handleLogin} color="#ff00ff" />
|
||||
<Button title="Regisztráció" onPress={handleRegister} color="#ff00ff" />
|
||||
<Text onPress={() => setIsAdmin(!isAdmin)} style={styles.toggle}>
|
||||
{isAdmin ? 'Admin mód' : 'User mód'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16, justifyContent: 'center', backgroundColor: '#000000' },
|
||||
input: { borderWidth: 1, borderColor: '#333333', padding: 8, marginBottom: 16, borderRadius: 4, backgroundColor: '#1a1a1a', color: '#ffffff' },
|
||||
toggle: { marginTop: 16, textAlign: 'center', color: '#ff00ff' },
|
||||
});
|
||||
43
screens/ProfileScreen.tsx
Normal file
43
screens/ProfileScreen.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, TextInput, Button, StyleSheet } from 'react-native';
|
||||
import { signOut } from 'firebase/auth';
|
||||
import { doc, getDoc, updateDoc } from 'firebase/firestore';
|
||||
import { auth, db } from '../config/firebase';
|
||||
|
||||
export default function ProfileScreen({ navigation }: any) {
|
||||
const [name, setName] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
loadProfile();
|
||||
}, []);
|
||||
|
||||
const loadProfile = async () => {
|
||||
const userDoc = await getDoc(doc(db, 'users', auth.currentUser!.uid));
|
||||
setName(userDoc.data()?.name || '');
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
await updateDoc(doc(db, 'users', auth.currentUser!.uid), { name });
|
||||
alert('Profil mentve');
|
||||
};
|
||||
|
||||
const handleLogout = async () => {
|
||||
await signOut(auth);
|
||||
navigation.replace('Login');
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.title}>Profil</Text>
|
||||
<TextInput style={styles.input} placeholder="Név" value={name} onChangeText={setName} />
|
||||
<Button title="Mentés" onPress={handleSave} />
|
||||
<Button title="Kijelentkezés" onPress={handleLogout} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16, justifyContent: 'center' },
|
||||
title: { fontSize: 24, fontWeight: 'bold', marginBottom: 16, textAlign: 'center' },
|
||||
input: { borderWidth: 1, padding: 8, marginBottom: 16, borderRadius: 4 },
|
||||
});
|
||||
Reference in New Issue
Block a user