瀏覽代碼

Upload files to 'screens'

dayanlee.deleon 2 年之前
父節點
當前提交
31f40a4ae9
共有 2 個文件被更改,包括 215 次插入0 次删除
  1. 150
    0
      screens/createAccount.js
  2. 65
    0
      screens/loggedIn.js

+ 150
- 0
screens/createAccount.js 查看文件

@@ -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
+});

+ 65
- 0
screens/loggedIn.js 查看文件

@@ -0,0 +1,65 @@
1
+import * as React from 'react';
2
+import { Alert, View, Linking} from 'react-native';
3
+import { Button, Text, TextInput, Divider } from 'react-native-paper';
4
+import { useCallback } from "react";
5
+import { createStackNavigator, createAppContainer } from 'react-navigation';  
6
+
7
+const supportedURL = "https://docs.google.com/forms/d/e/1FAIpQLSe93-cuCFQ084AxVbzhwFJHjtPhrXFJ624ezAcqKU5qUsBqwg/viewform";
8
+
9
+const OpenURLButton = ({ url, children }) => {
10
+    const handlePress = useCallback(async () => {
11
+      // Checking if the link is supported for links with custom URL scheme.
12
+      const supported = await Linking.canOpenURL(url);
13
+  
14
+      if (supported) {
15
+        // Opening the link with some app, if the URL scheme is "http" the web link should be opened
16
+        // by some browser in the mobile
17
+        await Linking.openURL(url);
18
+      } else {
19
+        Alert.alert(`Don't know how to open this URL: ${url}`);
20
+      }
21
+    }, [url]);
22
+  
23
+    return <Button buttonColor = "purple" 
24
+            textColor= "white"
25
+            style={{width: 250, marginVertical: 40, marginHorizontal: 90}}
26
+            onPress={handlePress}>
27
+                Llenar formulario de voluntario
28
+            </Button> ;
29
+  };
30
+
31
+
32
+const MyComponent = () => {
33
+    const [text, setText] = React.useState("");
34
+    const [text2, setText2] = React.useState("");
35
+
36
+
37
+  return (
38
+    <View >
39
+
40
+        <Text style={{fontSize:30, fontWeight:"bold",  marginVertical: 20, marginHorizontal: 30}}>
41
+            Mi Cuenta
42
+        </Text>
43
+    
44
+        <Text style={{fontSize:15, fontWeight:"bold",  marginVertical: 20, marginHorizontal: 30}}>
45
+            Nombre:
46
+        </Text>
47
+
48
+        <Text style={{fontSize:15, fontWeight:"bold",  marginVertical: 20, marginHorizontal: 30}}>
49
+            Email:
50
+        </Text>
51
+
52
+        <Text style={{fontSize:15, fontWeight:"bold",  marginVertical: 20, marginHorizontal: 30}}>
53
+            Teléfono:
54
+        </Text>
55
+    
56
+        <OpenURLButton 
57
+        url={"https://docs.google.com/forms/d/e/1FAIpQLSe93-cuCFQ084AxVbzhwFJHjtPhrXFJ624ezAcqKU5qUsBqwg/viewform"}>
58
+            Llenar formulario de voluntario
59
+        </OpenURLButton>
60
+        
61
+    </View>
62
+  );
63
+};
64
+
65
+export default MyComponent;