|
| 1 | +/** |
| 2 | +* This is the Signup Page |
| 3 | +**/ |
| 4 | + |
| 5 | +// React native and others libraries imports |
| 6 | +import React, { Component } from 'react'; |
| 7 | +import { ScrollView } from 'react-native'; |
| 8 | +import { Container, View, Left, Right, Button, Icon, Item, Input } from 'native-base'; |
| 9 | +import { Actions } from 'react-native-router-flux'; |
| 10 | + |
| 11 | +// Our custom files and classes import |
| 12 | +import Colors from '../Colors'; |
| 13 | +import Text from '../component/Text'; |
| 14 | +import Navbar from '../component/Navbar'; |
| 15 | + |
| 16 | +export default class Signup extends Component { |
| 17 | + constructor(props) { |
| 18 | + super(props); |
| 19 | + this.state = { |
| 20 | + email: '', |
| 21 | + name: '', |
| 22 | + username: '', |
| 23 | + password: '', |
| 24 | + rePassword: '', |
| 25 | + hasError: false, |
| 26 | + errorText: '' |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + render() { |
| 32 | + var left = ( |
| 33 | + <Left style={{flex:1}}> |
| 34 | + <Button onPress={() => Actions.pop()} transparent> |
| 35 | + <Icon name='ios-arrow-back' /> |
| 36 | + </Button> |
| 37 | + </Left> |
| 38 | + ); |
| 39 | + var right = ( |
| 40 | + <Right style={{flex:1}}> |
| 41 | + <Button onPress={() => Actions.search()} transparent> |
| 42 | + <Icon name='ios-search-outline' /> |
| 43 | + </Button> |
| 44 | + <Button onPress={() => Actions.cart()} transparent> |
| 45 | + <Icon name='ios-cart' /> |
| 46 | + </Button> |
| 47 | + </Right> |
| 48 | + ); |
| 49 | + return( |
| 50 | + <Container style={{backgroundColor: '#fdfdfd'}}> |
| 51 | + <Navbar left={left} right={right} title="SIGN UP" /> |
| 52 | + <ScrollView contentContainerStyle={{flexGrow: 1}}> |
| 53 | + <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', paddingLeft: 50, paddingRight: 50}}> |
| 54 | + <View style={{marginBottom: 35, width: '100%'}}> |
| 55 | + <Text style={{fontSize: 24, fontWeight: 'bold', textAlign: 'left', width: '100%', color: Colors.navbarBackgroundColor}}>Create your account, </Text> |
| 56 | + <Text style={{fontSize: 18, textAlign: 'left', width: '100%', color: '#687373'}}>Signup to continue </Text> |
| 57 | + </View> |
| 58 | + <Item> |
| 59 | + <Icon active name='ios-mail' style={{color: '#687373'}} /> |
| 60 | + <Input placeholder='Email' onChangeText={(text) => this.setState({email: text})} keyboardType="email-address" placeholderTextColor="#687373" /> |
| 61 | + </Item> |
| 62 | + <Item> |
| 63 | + <Icon active name='ios-man' style={{color: '#687373'}} /> |
| 64 | + <Input placeholder='Name' onChangeText={(text) => this.setState({name: text})} placeholderTextColor="#687373" /> |
| 65 | + </Item> |
| 66 | + <Item> |
| 67 | + <Icon active name='ios-person' style={{color: '#687373'}} /> |
| 68 | + <Input placeholder='Username' onChangeText={(text) => this.setState({username: text})} placeholderTextColor="#687373" /> |
| 69 | + </Item> |
| 70 | + <Item> |
| 71 | + <Icon active name='ios-lock' style={{color: '#687373'}} /> |
| 72 | + <Input placeholder='Password' onChangeText={(text) => this.setState({password: text})} secureTextEntry={true} placeholderTextColor="#687373" /> |
| 73 | + </Item> |
| 74 | + <Item> |
| 75 | + <Icon active name='ios-lock' style={{color: '#687373'}} /> |
| 76 | + <Input placeholder='Repeat your password' onChangeText={(text) => this.setState({rePassword: text})} secureTextEntry={true} placeholderTextColor="#687373" /> |
| 77 | + </Item> |
| 78 | + {this.state.hasError?<Text style={{color: "#c0392b", textAlign: 'center', marginTop: 10}}>{this.state.errorText}</Text>:null} |
| 79 | + <View style={{alignItems: 'center'}}> |
| 80 | + <Button onPress={() => this.signup()} style={{backgroundColor: Colors.navbarBackgroundColor, marginTop: 20}}> |
| 81 | + <Text style={{color: '#fdfdfd'}}>Signup</Text> |
| 82 | + </Button> |
| 83 | + </View> |
| 84 | + </View> |
| 85 | + </ScrollView> |
| 86 | + </Container> |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + signup() { |
| 91 | + if(this.state.email===""||this.state.name===""||this.state.username===""||this.state.password===""||this.state.rePassword==="") { |
| 92 | + this.setState({hasError: true, errorText: 'Please fill all fields !'}); |
| 93 | + return; |
| 94 | + } |
| 95 | + if(!this.verifyEmail(this.state.email)) { |
| 96 | + this.setState({hasError: true, errorText: 'Please enter a valid email address !'}); |
| 97 | + return; |
| 98 | + } |
| 99 | + if(this.state.username.length < 3) { |
| 100 | + this.setState({hasError: true, errorText: 'Passwords must contains at least 3 characters !'}); |
| 101 | + return; |
| 102 | + } |
| 103 | + if(this.state.password.length < 6) { |
| 104 | + this.setState({hasError: true, errorText: 'Passwords must contains at least 6 characters !'}); |
| 105 | + return; |
| 106 | + } |
| 107 | + if(this.state.password !== this.state.rePassword) { |
| 108 | + this.setState({hasError: true, errorText: 'Passwords does not match !'}); |
| 109 | + return; |
| 110 | + } |
| 111 | + this.setState({hasError: false}); |
| 112 | + Actions.home(); |
| 113 | + } |
| 114 | + |
| 115 | + verifyEmail(email) { |
| 116 | + 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,}))$/; |
| 117 | + return reg.test(email); |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | +} |
0 commit comments