-
Notifications
You must be signed in to change notification settings - Fork 0
/
Userreg.js
110 lines (95 loc) · 3.61 KB
/
Userreg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { useState } from 'react';
import { Avatar } from 'react-native-elements';
import { StyleSheet } from 'react-native';
function UserRegistration() {
const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const handleRegister = () => {
let errorMessage = null; // Initialize error message variable
if (!username) {
errorMessage = 'Please enter a username.';
} else if (!email) {
errorMessage = 'Please enter an email address.';
} else if (!password) {
errorMessage = 'Please enter a password.';
} else if (password !== confirmPassword) {
errorMessage = 'Passwords do not match.';
}
if (errorMessage) {
Alert.alert('Registration Error', errorMessage); // Display error message using Alert
return; // Prevent further processing if validation fails
}
console.log('Registering user...', username, email);
// Add validation checks here (e.g., empty fields, password strength)
// If validation passes, call a function to securely store user data (e.g., using AsyncStorage)
// Navigate to a different screen (e.g., login screen or main app screen) after successful registration
};
return (
<View style={styles.container}>
<Avatar
rounded
size = "large"
source={{ uri: 'https://placeimg.com/150/150/people' }} // Placeholder image
onPress={() => console.log('Avatar clicked!')} // Optional onPress handler
/>
<Text style={styles.title}>Emergency Assistance App Vanya</Text>
<TextInput
style={styles.input}
placeholder="Username"
value={username}
onChangeText={setUsername}
autoCapitalize="none" // Prevent automatic capitalization
/>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
keyboardType="email-address" // Set keyboard type for email
/>
<TextInput
style={styles.input}
placeholder="Password"
value={password}
onChangeText={setPassword}
secureTextEntry={true} // Hide password characters
/>
<TextInput
style={styles.input}
placeholder="Confirm Password"
value={confirmPassword}
onChangeText={setConfirmPassword}
secureTextEntry={true} // Hide password characters
/>
{password !== confirmPassword && <Text style={styles.error}>Passwords don't match</Text>} {/* Placeholder for error message */}
<Button title="Register" onPress={handleRegister} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
title: {
fontSize: 30,
marginBottom: 20,
},
input: {
height: 40,
width: '100%',
borderColor: 'gray',
borderWidth: 1,
marginBottom: 10,
padding: 8,
},
error: {
color: 'red',
marginBottom: 10,
},
});
export default UserRegistration;