|
@@ -0,0 +1,150 @@
|
|
1
|
+import * as React from 'react';
|
|
2
|
+import * as WebBrowser from 'expo-web-browser';
|
|
3
|
+import * as Google from 'expo-auth-session/providers/google';
|
|
4
|
+import { StyleSheet, View, Image, TouchableOpacity} from 'react-native';
|
|
5
|
+import { StatusBar } from 'expo-status-bar';
|
|
6
|
+import { Button, Text, TextInput, Divider } from 'react-native-paper';
|
|
7
|
+
|
|
8
|
+WebBrowser.maybeCompleteAuthSession();
|
|
9
|
+
|
|
10
|
+export default function About({navigation}) {
|
|
11
|
+ const [accessToken, setAccessToken] = React.useState(null);
|
|
12
|
+ const [user, setUser] = React.useState(null);
|
|
13
|
+ const [text, setText] = React.useState(null);
|
|
14
|
+ const [text2, setText2] = React.useState(null);
|
|
15
|
+ const [text3, setText3] = React.useState(null);
|
|
16
|
+ const [request, response, promptAsync] = Google.useAuthRequest({
|
|
17
|
+ clientId:"651131042419-nku2iod9kjulk7g2ipj8v51v842c1j9o.apps.googleusercontent.com",
|
|
18
|
+ iosClientId: "651131042419-7lu7jen40pbkifledd8ed8itkvo6255b.apps.googleusercontent.com",
|
|
19
|
+ });
|
|
20
|
+
|
|
21
|
+ React.useEffect(() => {
|
|
22
|
+ if(response?.type === "success") {
|
|
23
|
+ setAccessToken(response.authentication.accessToken);
|
|
24
|
+ accessToken && fetchUserInfo();
|
|
25
|
+ }
|
|
26
|
+ }, [response, accessToken])
|
|
27
|
+
|
|
28
|
+ const fetchUserInfo = async () => {
|
|
29
|
+ let response = await fetch("https://www.googleapis.com/userinfo/v2/me", {
|
|
30
|
+ headers: {Authorization: `Bearer ${accessToken}`}
|
|
31
|
+ })
|
|
32
|
+
|
|
33
|
+ response.json().then(data => {
|
|
34
|
+ setUser(data);
|
|
35
|
+ })
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ const ShowUserInfo = () => {
|
|
39
|
+ if(user) {
|
|
40
|
+ return(
|
|
41
|
+ <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
|
|
42
|
+ <Text style={{fontSize: 35, fontWeight: 'bold', marginBottom: 20}}>Welcome</Text>
|
|
43
|
+ <Image source={{uri: user.picture}} style={styles.profilePic} />
|
|
44
|
+ {console.log(user.name)}
|
|
45
|
+ </View>
|
|
46
|
+ )
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ const InsertDataToServer = () => {
|
|
51
|
+
|
|
52
|
+ fetch('https://ada.uprrp.edu/~pablo.puig1/TPMG/loginUserAdd.php', {
|
|
53
|
+ method: 'POST',
|
|
54
|
+ headers: {
|
|
55
|
+ 'Accept': 'application/json',
|
|
56
|
+ 'Content-Type': 'application/json',
|
|
57
|
+ },
|
|
58
|
+ body: JSON.stringify({
|
|
59
|
+
|
|
60
|
+ name: text,
|
|
61
|
+
|
|
62
|
+ email: text2,
|
|
63
|
+
|
|
64
|
+ phone: text3
|
|
65
|
+
|
|
66
|
+ })
|
|
67
|
+ }).then((response) => response.json())
|
|
68
|
+ .then((responseJson) => {
|
|
69
|
+
|
|
70
|
+ // Showing response message coming from server after inserting records.
|
|
71
|
+ Alert.alert(responseJson);
|
|
72
|
+
|
|
73
|
+ }).catch((error) => {
|
|
74
|
+ console.error(error);
|
|
75
|
+ });
|
|
76
|
+
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ return (
|
|
80
|
+ <View style={styles.container}>
|
|
81
|
+
|
|
82
|
+ <Text style={{fontSize:30, fontWeight:"bold", marginVertical: 0, marginHorizontal: 80}}>
|
|
83
|
+ Crear Cuenta
|
|
84
|
+ </Text>
|
|
85
|
+
|
|
86
|
+ <TextInput style={{width: 350, marginVertical: 40, marginHorizontal: 10}}
|
|
87
|
+ label="Nombre"
|
|
88
|
+ value={text}
|
|
89
|
+ mode = "outlined"
|
|
90
|
+ outlineColor='#327ABC'
|
|
91
|
+ onChangeText={text => setText(text)}
|
|
92
|
+ />
|
|
93
|
+
|
|
94
|
+ <TextInput style={{width: 350, marginVertical: -20, marginHorizontal: 10}}
|
|
95
|
+ label="Email"
|
|
96
|
+ value={text2}
|
|
97
|
+ mode = "outlined"
|
|
98
|
+ outlineColor='#327ABC'
|
|
99
|
+ onChangeText={text2 => setText2(text2)}
|
|
100
|
+ />
|
|
101
|
+
|
|
102
|
+ <TextInput style={{width: 350, marginVertical: 40, marginHorizontal: 10}}
|
|
103
|
+ label="Número de telefono"
|
|
104
|
+ value={text3}
|
|
105
|
+ mode = "outlined"
|
|
106
|
+ outlineColor='#327ABC'
|
|
107
|
+ onChangeText={text3 => setText3(text3)}
|
|
108
|
+ />
|
|
109
|
+
|
|
110
|
+<Button style={{width: 250, marginVertical: 40, marginHorizontal: 60}}
|
|
111
|
+ buttonColor = "#327ABC"
|
|
112
|
+ mode="contained"
|
|
113
|
+ onPress={()=> {InsertDataToServer(); navigation.navigate('Profile', {userName:text, email:text2, phone:text3})}}>
|
|
114
|
+ Crear cuenta
|
|
115
|
+ </Button>
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+ <Divider style={{marginVertical: -20}}
|
|
121
|
+ horizontalInset='true' />
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+ <Button style={{width: 250, marginVertical: 70, marginHorizontal: 60}}
|
|
126
|
+ buttonColor = "teal"
|
|
127
|
+ mode="contained"
|
|
128
|
+ onPress={accessToken ? fetchUserInfo: () => promptAsync({useProxy:true, showInRecents:true})}>
|
|
129
|
+ Crear cuenta con Google
|
|
130
|
+ </Button>
|
|
131
|
+
|
|
132
|
+ </View>
|
|
133
|
+ );
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+}
|
|
137
|
+
|
|
138
|
+const styles = StyleSheet.create({
|
|
139
|
+ container: {
|
|
140
|
+ padding: 24
|
|
141
|
+ },
|
|
142
|
+ profilePic: {
|
|
143
|
+ width: 50,
|
|
144
|
+ height: 50
|
|
145
|
+ },
|
|
146
|
+ userInfo: {
|
|
147
|
+ alignItems: 'center',
|
|
148
|
+ justifyContent: 'center'
|
|
149
|
+ }
|
|
150
|
+});
|