Browse Source

Upload files to ''

mortimel.ojeda 2 years ago
parent
commit
f609c39a7d
2 changed files with 94 additions and 0 deletions
  1. 38
    0
      LoginScreen.js
  2. 56
    0
      RegisterScreen.js

+ 38
- 0
LoginScreen.js View File

@@ -0,0 +1,38 @@
1
+import React, { Component } from "react";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Image } from "react-native";
3
+import firebase from "firebase";
4
+
5
+import { styles } from "../config/styles";
6
+import CustomButton from "../components/CustomButton";
7
+
8
+
9
+export default class LoginScreen extends Component {
10
+    constructor(props) {
11
+        super(props);
12
+        this.state = {
13
+            email: '',
14
+            password: '',
15
+        };
16
+        this.onLogin = this.onLogin.bind(this)
17
+    };
18
+
19
+    onLogin() {
20
+        const { email, password } = this.state;
21
+        firebase.auth().signInWithEmailAndPassword(email, password).then((result) => {console.log(result)}).catch((error) => {console.log(error)})
22
+    }
23
+
24
+    render() {
25
+        
26
+        return (
27
+            <TouchableWithoutFeedback style={styles.stdcontainer} onPress={Keyboard.dismiss} accessible={false}>
28
+                <ImageBackground style={styles.stdcontainer} source={require('../assets/yellow-white.jpg')}>
29
+                    <Image style={styles.logo} resizeMode="contain" source={require("../assets/open-hand.png")}/>
30
+                    <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
31
+                    <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>
32
+                    <CustomButton marginTop={70} title="Login" onPress={() => this.onLogin()}/>
33
+                    <CustomButton marginTop={25} title="Register" onPress={() => this.props.navigation.navigate('Register')}/>
34
+                </ImageBackground>
35
+            </TouchableWithoutFeedback>
36
+        );
37
+    }
38
+}

+ 56
- 0
RegisterScreen.js View File

@@ -0,0 +1,56 @@
1
+import React, { Component } from "react";
2
+import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground, Text, View } from "react-native";
3
+import firebase from "firebase";
4
+import { Picker } from "@react-native-picker/picker";
5
+
6
+import { styles } from "../config/styles";
7
+import CustomButton from "../components/CustomButton";
8
+
9
+export default class RegisterScreen extends Component {
10
+    constructor(props) {
11
+        super(props);
12
+        this.state = {
13
+            username: '',
14
+            email: '',
15
+            password: '',
16
+            interpreter: false,
17
+        };
18
+        this.onRegister = this.onRegister.bind(this)
19
+    };
20
+
21
+    onRegister() {
22
+        const { username, email, password, interpreter } = this.state;
23
+        firebase.auth().createUserWithEmailAndPassword(email, password)
24
+            .then((result) => {
25
+                firebase.firestore().collection("Users")
26
+                    .doc(firebase.auth().currentUser.uid)
27
+                    .set({
28
+                        username,
29
+                        email,
30
+                        interpreter,
31
+                    })
32
+                console.log(result)
33
+            })
34
+            .catch((error) => {
35
+                console.log(error)
36
+            })
37
+    }
38
+
39
+    render() {
40
+        return (
41
+            <TouchableWithoutFeedback style={styles.regcontainer} onPress={Keyboard.dismiss} accessible={false}>
42
+                <ImageBackground style={styles.regcontainer} source={require('../assets/yellow-white.jpg')}>
43
+                    <TextInput style={styles.regtxtfield} placeholder="Userame" onChangeText={(username) => this.setState({ username })}/>
44
+                    <TextInput style={styles.regtxtfield} placeholder="Email" onChangeText={(email) => this.setState({ email })}/>
45
+                    <TextInput style={styles.regtxtfield} placeholder="Password" onChangeText={(password) => this.setState({ password })} secureTextEntry={ true }/>
46
+                    <Text style={styles.qsttxt}>Are you an interpreter?</Text>
47
+                    <Picker style={styles.picker} selectedValue={this.state.interpreter} onValueChange={(itemValue,itemIndex) => this.setState({interpreter: itemValue})}>
48
+                        <Picker.Item label="Yes" value={true}/>
49
+                        <Picker.Item label="No" value={false}/>
50
+                    </Picker>
51
+                    <CustomButton  marginTop={50} title="Register" onPress={() => this.onRegister()}/>
52
+                </ImageBackground>
53
+            </TouchableWithoutFeedback>
54
+        );
55
+    }
56
+}