-
Notifications
You must be signed in to change notification settings - Fork 0
/
SigIn.js
232 lines (216 loc) · 6.11 KB
/
SigIn.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import { StatusBar } from "expo-status-bar";
import * as React from "react";
import {
View,
Text,
Image,
TouchableOpacity,
useWindowDimensions,
TextInput,
} from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp,
} from "react-native-responsive-screen";
import { initializeApp } from "firebase/app";
import { createUserWithEmailAndPassword, getAuth } from "firebase/auth";
import {
addDoc,
doc,
collection,
getFirestore,
getDocs,
query,
deleteDoc,
orderBy,
startAfter,
limit,
startAt,
endBefore,
updateDoc,
setDoc,
getDoc,
where,
} from "firebase/firestore/";
const SigIn = ({ route, navigation }) => {
//per dimensioni finestra in real time
const winSize = useWindowDimensions();
//prendo auth firebase inizializzato in login
const auth = route.params.auth;
//inizializzo databsee firebase
const db = getFirestore();
let [nome, setNome] = React.useState("");
let [cognome, setCognome] = React.useState("");
let [email, setEmail] = React.useState("");
let [password, setPassword] = React.useState("");
let registrati = () => {
if (nome != "" && cognome != "" && email != "" && password != "") {
if (password.length >= 6) {
//creo nyovo utente se tutti campi compilati e email non esistente già e password più lunga di 6 caratteri
createUserWithEmailAndPassword(auth, email.trim(), password.trim())
.then(() => {
//salvo nome e cognome
setDoc(doc(db, "Utenti", email.replaceAll(".", "DOT").trim()), {
nome: nome.trim(),
cognome: cognome.trim(),
});
navigation.goBack();
alert("Registration has been completed successfully");
})
.catch((err) => {
console.log(err);
alert("This email already exist or is invalid");
});
} else {
alert("Password has to be at least 6 character");
}
} else {
alert("Complete all fields");
}
};
return (
<View
style={{
width: "flex",
height: "100%",
backgroundColor: "#191919",
alignItems: "center",
}}
>
{/*Logo */}
<Image
resizeMode="center"
style={{
width: winSize.width / 2,
height: "250px",
marginTop: "-20px",
}}
source={{ uri: require("./assets/logo.png") }}
></Image>
<View
style={{
marginTop: hp("1%"),
borderRadius: 20,
width: winSize.width < 900 ? winSize.width - 100 : winSize.width / 3,
backgroundColor: "#2b2b2b",
justifyContent: "center",
alignItems: "center",
}}
>
{/*SigIn Text */}
<Text
style={{
color: "white",
fontSize: hp("5%"),
fontWeight: "200",
marginTop: hp("5%"),
}}
>
SigIn
</Text>
{/*Input Nome */}
<TextInput
style={{
marginTop: hp("3%"),
height: hp("5%"),
width: winSize.width < 900 ? winSize.width / 2 : winSize.width / 4,
borderColor: "black",
backgroundColor: "white",
borderWidth: "1px",
borderRadius: hp("5%"),
textAlign: "center",
}}
onChangeText={(text) => {
setNome(text);
}}
textContentType="name"
placeholder="Name"
></TextInput>
{/*Input Cognome */}
<TextInput
style={{
marginTop: hp("3%"),
height: hp("5%"),
width: winSize.width < 900 ? winSize.width / 2 : winSize.width / 4,
borderColor: "black",
backgroundColor: "white",
borderWidth: "1px",
borderRadius: hp("5%"),
textAlign: "center",
}}
onChangeText={(text) => {
setCognome(text);
}}
placeholder="Surname"
></TextInput>
{/*Input EMail */}
<TextInput
style={{
marginTop: hp("3%"),
height: hp("5%"),
width: winSize.width < 900 ? winSize.width / 2 : winSize.width / 4,
borderColor: "black",
borderWidth: "1px",
borderRadius: hp("5%"),
textAlign: "center",
backgroundColor: "white",
}}
onChangeText={(text) => {
setEmail(text);
}}
textContentType="emailAddress"
placeholder="Email"
></TextInput>
{/*Input Password */}
<TextInput
style={{
marginTop: hp("3%"),
height: hp("5%"),
width: winSize.width < 900 ? winSize.width / 2 : winSize.width / 4,
borderColor: "black",
borderWidth: "1px",
borderRadius: hp("5%"),
textAlign: "center",
backgroundColor: "white",
}}
onChangeText={(text) => {
setPassword(text);
}}
secureTextEntry="true"
passwordRules="true"
placeholder="Password"
></TextInput>
{/*Pulsante Registrati */}
<TouchableOpacity
style={{
marginTop: hp("3%"),
backgroundColor: "#ff5c5c",
width: "150px",
height: "40px",
justifyContent: "center",
alignItems: "center",
}}
onPress={() => {
registrati();
}}
>
<View>
<Text style={{ color: "white" }}>Send</Text>
</View>
</TouchableOpacity>
{/*goBack pulsante */}
<TouchableOpacity
style={{ marginTop: hp("2%"), marginBottom: hp("5%") }}
onPress={() => navigation.goBack()}
>
<Text style={{ fontSize: hp("2%"), fontWeight: 200, color: "white" }}>
Go back
</Text>
</TouchableOpacity>
</View>
</View>
);
};
export default SigIn;