Initial commit
This commit is contained in:
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Expo
|
||||||
|
.expo/
|
||||||
|
dist/
|
||||||
|
web-build/
|
||||||
|
expo-env.d.ts
|
||||||
|
|
||||||
|
# Native
|
||||||
|
.kotlin/
|
||||||
|
*.orig.*
|
||||||
|
*.jks
|
||||||
|
*.p8
|
||||||
|
*.p12
|
||||||
|
*.key
|
||||||
|
*.mobileprovision
|
||||||
|
|
||||||
|
# Metro
|
||||||
|
.metro-health-check*
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.*
|
||||||
|
yarn-debug.*
|
||||||
|
yarn-error.*
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# generated native folders
|
||||||
|
/ios
|
||||||
|
/android
|
||||||
35
App.tsx
Normal file
35
App.tsx
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
|
||||||
|
import { createStackNavigator } from '@react-navigation/stack';
|
||||||
|
import LoginScreen from './screens/LoginScreen';
|
||||||
|
import AdminScreen from './screens/AdminScreen';
|
||||||
|
import ProfileScreen from './screens/ProfileScreen';
|
||||||
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
||||||
|
|
||||||
|
const Stack = createStackNavigator();
|
||||||
|
|
||||||
|
const DarkTheme = {
|
||||||
|
...DefaultTheme,
|
||||||
|
colors: {
|
||||||
|
...DefaultTheme.colors,
|
||||||
|
primary: '#ff00ff',
|
||||||
|
background: '#000000',
|
||||||
|
card: '#1a1a1a',
|
||||||
|
text: '#ffffff',
|
||||||
|
border: '#333333',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||||
|
<NavigationContainer theme={DarkTheme}>
|
||||||
|
<Stack.Navigator screenOptions={{ headerShown: false }}>
|
||||||
|
<Stack.Screen name="Login" component={LoginScreen} />
|
||||||
|
<Stack.Screen name="Admin" component={AdminScreen} />
|
||||||
|
<Stack.Screen name="Profile" component={ProfileScreen} />
|
||||||
|
</Stack.Navigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
</GestureHandlerRootView>
|
||||||
|
);
|
||||||
|
}
|
||||||
28
app.json
Normal file
28
app.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"expo": {
|
||||||
|
"name": "feladat2-jogosultsagi-rendszer",
|
||||||
|
"slug": "feladat2-jogosultsagi-rendszer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"orientation": "portrait",
|
||||||
|
"icon": "./assets/icon.png",
|
||||||
|
"userInterfaceStyle": "light",
|
||||||
|
"newArchEnabled": true,
|
||||||
|
"splash": {
|
||||||
|
"image": "./assets/splash-icon.png",
|
||||||
|
"resizeMode": "contain",
|
||||||
|
"backgroundColor": "#ffffff"
|
||||||
|
},
|
||||||
|
"ios": {
|
||||||
|
"supportsTablet": true
|
||||||
|
},
|
||||||
|
"android": {
|
||||||
|
"adaptiveIcon": {
|
||||||
|
"foregroundImage": "./assets/adaptive-icon.png",
|
||||||
|
"backgroundColor": "#ffffff"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"web": {
|
||||||
|
"favicon": "./assets/favicon.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
assets/adaptive-icon.png
Normal file
BIN
assets/adaptive-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
assets/favicon.png
Normal file
BIN
assets/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
assets/splash-icon.png
Normal file
BIN
assets/splash-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
16
config/firebase.ts
Normal file
16
config/firebase.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { initializeApp } from 'firebase/app';
|
||||||
|
import { getAuth } from 'firebase/auth';
|
||||||
|
import { getFirestore } from 'firebase/firestore';
|
||||||
|
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: "AIzaSyCvVobBc9sBJRGygFedExwITXCFW13R4ds",
|
||||||
|
authDomain: "gyakorlatifeladatok-6c7c0.firebaseapp.com",
|
||||||
|
projectId: "gyakorlatifeladatok-6c7c0",
|
||||||
|
storageBucket: "gyakorlatifeladatok-6c7c0.firebasestorage.app",
|
||||||
|
messagingSenderId: "721534659717",
|
||||||
|
appId: "1:721534659717:web:d7532753d6d6b0c009cdec"
|
||||||
|
};
|
||||||
|
|
||||||
|
const app = initializeApp(firebaseConfig);
|
||||||
|
export const auth = getAuth(app);
|
||||||
|
export const db = getFirestore(app);
|
||||||
8
index.ts
Normal file
8
index.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { registerRootComponent } from 'expo';
|
||||||
|
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
||||||
|
// It also ensures that whether you load the app in Expo Go or in a native build,
|
||||||
|
// the environment is set up appropriately
|
||||||
|
registerRootComponent(App);
|
||||||
5
metro.config.js
Normal file
5
metro.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const { getDefaultConfig } = require('expo/metro-config');
|
||||||
|
|
||||||
|
const config = getDefaultConfig(__dirname);
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
10016
package-lock.json
generated
Normal file
10016
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
Normal file
30
package.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "feladat2-jogosultsagi-rendszer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"start": "expo start",
|
||||||
|
"android": "expo start --android",
|
||||||
|
"ios": "expo start --ios",
|
||||||
|
"web": "expo start --web"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
||||||
|
"@react-native-community/netinfo": "11.4.1",
|
||||||
|
"@react-navigation/native": "^7.1.28",
|
||||||
|
"@react-navigation/stack": "^7.7.2",
|
||||||
|
"expo": "~54.0.33",
|
||||||
|
"expo-status-bar": "~3.0.9",
|
||||||
|
"firebase": "^12.9.0",
|
||||||
|
"react": "19.1.0",
|
||||||
|
"react-native": "0.81.5",
|
||||||
|
"react-native-gesture-handler": "~2.28.0",
|
||||||
|
"react-native-safe-area-context": "~5.6.0",
|
||||||
|
"react-native-screens": "~4.16.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "~19.1.0",
|
||||||
|
"typescript": "~5.9.2"
|
||||||
|
},
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
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 },
|
||||||
|
});
|
||||||
6
tsconfig.json
Normal file
6
tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "expo/tsconfig.base",
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user