-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signup.js
135 lines (114 loc) · 3.75 KB
/
Signup.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
import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity, SecureTextEntry} from 'react-native';
import Favorites from "./Favorites"
class Signup extends Component {
state={
username: "",
password: "",
password2: ""
}
signupHandler=(state)=>{
if (!state.username || !state.password || !state.password2) {
alert("Please enter valid username/password")
} else{
if (state.password === state.password2) {
fetch("http://localhost:3000/users", {
headers: {
'content-type': 'application/json',
'accept': 'application/json'
},
method: 'POST',
body: JSON.stringify({
user: {
username: state.username,
password: state.password
}
}),
})
.then(response => response.json())
.then(data => {
if (data.errors) {
alert(data.errors)
} else {
this.props.clickHandler(this.state)
}
})
} else {
alert("Passwords must match")
this.setState({
password: "",
password2: ""
})
}
}
}
render(){
return (
<View style={styles.container}>
<Text style={styles.centerTitle}>Create Account</Text>
<TextInput style={styles.inputBox}
onChangeText={(username) => this.setState({username})}
placeholder="Username"
placeholderTextColor = "#002f6c"
selectionColor="#fff"/>
<TextInput style={styles.inputBox}
onChangeText={(password) => this.setState({password})}
placeholder="Password"
secureTextEntry={true}
type="password"
placeholderTextColor = "#002f6c"
/>
<TextInput style={styles.inputBox}
onChangeText={(password2) => this.setState({password2})}
placeholder="Re-enter Password"
secureTextEntry={true}
type="password"
placeholderTextColor = "#002f6c"
/>
<TouchableOpacity style={styles.button}>
<Text onPress={()=>this.signupHandler(this.state)} style={styles.buttonText} >Sign Up</Text>
</TouchableOpacity>
<Text>Have An Account Already? <Text style={{color: 'blue'}}
onPress={() => this.props.loginHandler()}>Log In</Text></Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
},
inputBox: {
width: 290,
backgroundColor: '#eeeeee',
borderRadius: 25,
paddingHorizontal: 16,
fontSize: 16,
color: '#002f6c',
marginVertical: 10
},
button: {
width: 300,
backgroundColor: '#FF6700',
borderRadius: 25,
marginVertical: 10,
paddingVertical: 12
},
buttonText: {
fontSize: 16,
fontWeight: '500',
color: '#ffffff',
textAlign: 'center'
},
centerTitle: {
color: "black",
fontWeight: "bold",
fontSize: 25,
textAlign: "center",
marginTop: 20,
marginBottom: 8,
// fontFamily: ""
},
});
export default Signup;