forked from atef-najar/react-native-shop-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signup.js
121 lines (112 loc) · 4.79 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
/**
* This is the Signup Page
**/
// React native and others libraries imports
import React, { Component } from 'react';
import { ScrollView } from 'react-native';
import { Container, View, Left, Right, Button, Icon, Item, Input } from 'native-base';
import { Actions } from 'react-native-router-flux';
// Our custom files and classes import
import Colors from '../Colors';
import Text from '../component/Text';
import Navbar from '../component/Navbar';
export default class Signup extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
name: '',
username: '',
password: '',
rePassword: '',
hasError: false,
errorText: ''
};
}
render() {
var left = (
<Left style={{flex:1}}>
<Button onPress={() => Actions.pop()} transparent>
<Icon name='ios-arrow-back' />
</Button>
</Left>
);
var right = (
<Right style={{flex:1}}>
<Button onPress={() => Actions.search()} transparent>
<Icon name='ios-search-outline' />
</Button>
<Button onPress={() => Actions.cart()} transparent>
<Icon name='ios-cart' />
</Button>
</Right>
);
return(
<Container style={{backgroundColor: '#fdfdfd'}}>
<Navbar left={left} right={right} title="SIGN UP" />
<ScrollView contentContainerStyle={{flexGrow: 1}}>
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center', paddingLeft: 50, paddingRight: 50}}>
<View style={{marginBottom: 35, width: '100%'}}>
<Text style={{fontSize: 24, fontWeight: 'bold', textAlign: 'left', width: '100%', color: Colors.navbarBackgroundColor}}>Create your account, </Text>
<Text style={{fontSize: 18, textAlign: 'left', width: '100%', color: '#687373'}}>Signup to continue </Text>
</View>
<Item>
<Icon active name='ios-mail' style={{color: '#687373'}} />
<Input placeholder='Email' onChangeText={(text) => this.setState({email: text})} keyboardType="email-address" placeholderTextColor="#687373" />
</Item>
<Item>
<Icon active name='ios-man' style={{color: '#687373'}} />
<Input placeholder='Name' onChangeText={(text) => this.setState({name: text})} placeholderTextColor="#687373" />
</Item>
<Item>
<Icon active name='ios-person' style={{color: '#687373'}} />
<Input placeholder='Username' onChangeText={(text) => this.setState({username: text})} placeholderTextColor="#687373" />
</Item>
<Item>
<Icon active name='ios-lock' style={{color: '#687373'}} />
<Input placeholder='Password' onChangeText={(text) => this.setState({password: text})} secureTextEntry={true} placeholderTextColor="#687373" />
</Item>
<Item>
<Icon active name='ios-lock' style={{color: '#687373'}} />
<Input placeholder='Repeat your password' onChangeText={(text) => this.setState({rePassword: text})} secureTextEntry={true} placeholderTextColor="#687373" />
</Item>
{this.state.hasError?<Text style={{color: "#c0392b", textAlign: 'center', marginTop: 10}}>{this.state.errorText}</Text>:null}
<View style={{alignItems: 'center'}}>
<Button onPress={() => this.signup()} style={{backgroundColor: Colors.navbarBackgroundColor, marginTop: 20}}>
<Text style={{color: '#fdfdfd'}}>Signup</Text>
</Button>
</View>
</View>
</ScrollView>
</Container>
);
}
signup() {
if(this.state.email===""||this.state.name===""||this.state.username===""||this.state.password===""||this.state.rePassword==="") {
this.setState({hasError: true, errorText: 'Please fill all fields !'});
return;
}
if(!this.verifyEmail(this.state.email)) {
this.setState({hasError: true, errorText: 'Please enter a valid email address !'});
return;
}
if(this.state.username.length < 3) {
this.setState({hasError: true, errorText: 'Passwords must contains at least 3 characters !'});
return;
}
if(this.state.password.length < 6) {
this.setState({hasError: true, errorText: 'Passwords must contains at least 6 characters !'});
return;
}
if(this.state.password !== this.state.rePassword) {
this.setState({hasError: true, errorText: 'Passwords does not match !'});
return;
}
this.setState({hasError: false});
Actions.home();
}
verifyEmail(email) {
var reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
}