// screens/ProfileScreen.js import React, { useContext } from 'react'; import { View,…
- User
// screens/ProfileScreen.js
import React, { useContext } from 'react'; import { View, StyleSheet, ScrollView, Alert } from 'react-native'; import { Title, Caption, Text, Button } from 'react-native-paper'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { AuthContext } from '../context/AuthContext'; import { useTheme } from 'react-native-paper';
/**
- Simple Profile Screen Component */ const ProfileScreen = ({ navigation }) => { const { user, logout } = useContext(AuthContext); const theme = useTheme(); // Access the current theme
// Handler for logout action const handleLogout = () => { Alert.alert( 'Logout', 'Are you sure you want to logout?', [ { text: 'Cancel', style: 'cancel' }, { text: 'Logout', style: 'destructive', onPress: () => logout(), }, ], { cancelable: true } ); };
return ( <ScrollView style={[styles.container, { backgroundColor: theme.colors.background }]}> {/* User Information Section */} <Title style={[styles.title, { color: theme.colors.text }]}>{user.name} <Caption style={[styles.caption, { color: theme.colors.text }]}>{user.email}
code{/* Logout Button */} <View style={styles.logoutSection}> <Button mode="contained" icon="logout" onPress={handleLogout} style={styles.logoutButton} contentStyle={styles.buttonContent} accessibilityLabel="Logout" accessibilityHint="Logs you out of the application" > Logout </Button> </View> </ScrollView>); };
const styles = StyleSheet.create({ container: { flex: 1, }, userInfoSection: { paddingHorizontal: 20, paddingVertical: 40, alignItems: 'center', // Center the user info backgroundColor: 'transparent', }, title: { fontSize: 26, fontWeight: 'bold', }, caption: { fontSize: 16, lineHeight: 16, marginTop: 5, }, logoutSection: { paddingHorizontal: 20, marginTop: 30, alignItems: 'center', // Center the logout button }, logoutButton: { width: '100%', // Make the button stretch across the container borderRadius: 5, backgroundColor: undefined, // Let the theme handle the color }, buttonContent: { height: 50, // Ensures consistent button height justifyContent: 'center', }, });
export default ProfileScreen;
// models/User.js
const mongoose = require('mongoose'); const bcrypt = require('bcryptjs');
const UserSchema = new mongoose.Schema({ username: { type: String, required: [true, 'Username is required'], unique: true, trim: true }, email: { type: String, required: [true, 'Email is required'], unique: true, trim: true, lowercase: true, match: [/\S+@\S+.\S+/, 'Email is invalid'] }, password: { type: String, required: [true, 'Password is required'], minlength: [6, 'Password must be at least 6 characters long'] }, role: { type: String, enum: ['user', 'admin'], default: 'user' }, desiredPhysique: { type: String, enum: { values: ['lean', 'muscular', 'athletic'], message: 'Desired Physique must be either lean, muscular, or athletic' }, required: [true, 'Desired Physique is required'] }, fitnessGoals: { type: [String], default: [] }, dietaryPreferences: { type: [String], default: [] }, dietaryRestrictions: { type: [String], default: [] }, }, { timestamps: true });
- Assistant