Advertisement
Guest User

register

a guest
Jun 7th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { View, Text, StyleSheet,TextInput,TouchableOpacity } from 'react-native';
  3. import LinearGradient from 'react-native-linear-gradient';
  4. import firebase from 'react-native-firebase'
  5.  
  6. class Register extends Component {
  7.  
  8. static navigationOptions={
  9. header:null
  10. }
  11.  
  12. constructor(props){
  13. super(props)
  14. this.state={
  15. email:'',
  16. password:'',
  17. username:'',
  18. confirmpass:''
  19. }
  20. }
  21.  
  22.  
  23. register(){
  24.  
  25.  
  26. const { navigate,pop } = this.props.navigation;
  27.  
  28. var db = firebase.database().ref(); //made a reference to the database here. for later use
  29.  
  30. const { email, password,confirmpass } = this.state;
  31.  
  32. if(this.state.password==this.state.confirmpass){
  33.  
  34. var reg = /^[a-zA-Z0-9._%+-]+\@ocpgroup+\.ma$/;
  35. if(reg.test(this.state.email) == true){
  36. console.log('valid')
  37.  
  38.  
  39.  
  40.  
  41. firebase.auth().createUserWithEmailAndPassword(email, password)
  42. .then(() => {
  43. //we need info / user id from firebase that we just created
  44. var user = firebase.auth().currentUser;
  45.  
  46. //lets store his name/details inside database
  47. firebase.database().ref().child('Friends').child(user.uid).set({
  48. email: this.state.email,
  49. uid: user.uid,
  50. name: this.state.username,
  51. image:"https://firebasestorage.googleapis.com/v0/b/unichatio-f63db.appspot.com/o/user.png?alt=media&token=644dcea8-1c60-4615-998c-8e29627b1f8b", //thi is just thumbnail
  52.  
  53. })
  54. alert('user created!')
  55.  
  56.  
  57. }).
  58.  
  59.  
  60. catch(function(error) {
  61. //its for error handling..
  62. var showErr = JSON.stringify(error.message)
  63. Alert.alert('Ohh Snapp..',showErr)
  64.  
  65. });
  66. }
  67. else{
  68. alert('sorry you are not member of ocp,the email must have user@ocpgroup.ma')
  69. }
  70. }
  71. else {
  72. alert("the password is incorrect")
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. }
  81.  
  82.  
  83. render() {
  84. return (
  85. <LinearGradient colors={['#31bb88','#18ac26']}
  86. style={{width:'100%',height:'100%'}}
  87. >
  88. <Text style={{fontSize:30,fontWeight:'bold',alignSelf:'center',color:'white',marginTop:120}}>-Register-</Text>
  89.  
  90.  
  91. <View style={{top:40,marginHorizontal:10,alignItems:'center'}}>
  92.  
  93. <TextInput
  94. style={styles.input}
  95. selectionColor={'#3d1767'}
  96.  
  97. onChangeText={(username) => this.setState({username})}
  98. multiline={false}
  99. placeholder="Username"
  100. autoCapitalize="none"
  101. keyboardType="email-address"
  102. autoCorrect={false}
  103. returnKeyType="next"
  104. onSubmitEditing={(event) => {
  105. this.refs.next.focus();
  106. }}
  107. underlineColorAndroid="transparent"
  108. placeholderTextColor="gray"
  109.  
  110. />
  111.  
  112.  
  113.  
  114.  
  115. <TextInput
  116. style={styles.input}
  117. selectionColor={'#3d1767'}
  118. ref='next'
  119.  
  120. onChangeText={(email) => this.setState({email})}
  121. multiline={false}
  122. placeholder="Email"
  123. autoCapitalize="none"
  124. keyboardType="email-address"
  125. autoCorrect={false}
  126. defaultValue='@ocpgroup.ma'
  127. returnKeyType="next"
  128. onSubmitEditing={(event) => {
  129. this.refs.SecondInput.focus();
  130. }}
  131. underlineColorAndroid="transparent"
  132. placeholderTextColor="gray"
  133.  
  134. />
  135.  
  136. <TextInput
  137. style={styles.input}
  138. selectionColor={'#3d1767'}
  139. ref='SecondInput'
  140. onChangeText={(password) => this.setState({password})}
  141. multiline={false}
  142. placeholder="Password"
  143. secureTextEntry
  144. autoCapitalize="none"
  145. autoCorrect={false}
  146. returnKeyType="done"
  147. onSubmitEditing={(event) => {
  148. this.refs.third.focus();
  149. }}
  150. underlineColorAndroid="transparent"
  151. placeholderTextColor="gray"
  152.  
  153. />
  154.  
  155.  
  156.  
  157. <TextInput
  158. style={styles.input}
  159. selectionColor={'#3d1767'}
  160. ref='third'
  161. onChangeText={(confirmpass) => this.setState({confirmpass})}
  162. multiline={false}
  163. placeholder="Confirm password"
  164. secureTextEntry
  165. autoCapitalize="none"
  166. autoCorrect={false}
  167. returnKeyType="done"
  168. underlineColorAndroid="transparent"
  169. placeholderTextColor="gray"
  170.  
  171. />
  172.  
  173.  
  174.  
  175.  
  176. <TouchableOpacity activeOpacity={0.8} onPress={()=>this.register()} style={{backgroundColor:'white',borderRadius:19,width:'75%',height:40,alignItems:'center',justifyContent:'center',borderWidth:2,borderColor:'rgba(0, 22, 0, 0.5)',marginTop:50}}>
  177. <Text style={{fontWeight:"700",fontSize:15,includeFontPadding:true,color:'#2c3e50'}}>REGISTER</Text>
  178. </TouchableOpacity>
  179.  
  180. <TouchableOpacity activeOpacity={0.8} onPress={()=>this.props.navigation.pop()} style={{backgroundColor:'white',borderRadius:19,width:'75%',height:40,alignItems:'center',justifyContent:'center',marginVertical:10,borderWidth:2,borderColor:'rgba(0, 22, 0, 0.5)'}}>
  181. <Text style={{fontWeight:"700",fontSize:15,includeFontPadding:true,color:'#2c3e50'}}>LOGIN</Text>
  182. </TouchableOpacity>
  183.  
  184.  
  185.  
  186. </View>
  187.  
  188. </LinearGradient>
  189. );
  190. }
  191. }
  192.  
  193. // define your styles
  194. const styles = StyleSheet.create({
  195. container: {
  196. flex: 1,
  197.  
  198. //alignItems:'center',
  199. justifyContent:'center',
  200. backgroundColor: '#00b894',
  201. },
  202. input:{
  203. marginVertical:4,
  204. paddingHorizontal:9,
  205. color:'black',
  206. fontSize:15,
  207. height:48,
  208. width:'100%',
  209. backgroundColor:'white'
  210.  
  211. }
  212. });
  213.  
  214. //make this component available to the app
  215. export default Register;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement