Guest User

Untitled

a guest
Apr 23rd, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StackNavigator } from 'react-navigation';
  3. import Label from '../components/Label';
  4. import { BACKEND_URL } from './config.js'
  5. import {
  6. StyleSheet,
  7. Text,
  8. Image,
  9. TextInput,
  10. TouchableOpacity,
  11. ScrollView,
  12. Linking,
  13. AsyncStorage,
  14. View,
  15. ActivityIndicator
  16. } from 'react-native';
  17. import FontAwesome from 'react-native-vector-icons/FontAwesome';
  18. import Feather from 'react-native-vector-icons/Feather';
  19. import { Icon } from 'react-native-elements'
  20. import SvgUri from 'react-native-svg-uri';
  21.  
  22. export default class LoginForm extends Component {
  23.  
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. username : '',
  28. email : '',
  29. user_pass : '',
  30. contact : '',
  31. signUpStatus: false
  32. }
  33. this.registerUser = this.registerUser.bind(this)
  34. }
  35.  
  36. registerUser = async () => {
  37. this.setState({
  38. signUpStatus: true
  39. })
  40. const response = await fetch(BACKEND_URL+'/api/user/register_user?username='+this.state.username+'&email='+this.state.email+'&user_pass='+this.state.user_pass+'&contact='+this.state.contact+'&insecure=cool',{
  41. method : 'POST',
  42. headers : {
  43. 'Accept' : 'application/json',
  44. 'Content-Type' : 'application/json',
  45. }
  46. })
  47. const data = await response.json()
  48. if(data.status === "ok"){
  49. this.setState({
  50. signUpStatus: false
  51. })
  52. await AsyncStorage.setItem('cokkie', data.cookie);
  53. this.props.navigation.navigate('Home');
  54. }
  55.  
  56. if(data.status == "error"){
  57. this.setState({
  58. signUpStatus: false
  59. })
  60. alert(data.error)
  61. }
  62. }
  63.  
  64. render() {
  65. const { navigate } = this.props.navigation;
  66.  
  67. return(
  68. <ScrollView style={styles.main}>
  69. {(this.state.signUpStatus)
  70. ? <View style={styles.overlay}>
  71. <ActivityIndicator size="large" color="#fff" />
  72. </View>
  73. : null
  74. }
  75. <View style={styles.box}>
  76. <View style={styles.container}>
  77. <View style={{alignSelf: 'center'}}>
  78. <Image source={require('../Image/logo.png')} style={styles.imageStyle} />
  79. </View>
  80. </View>
  81. <View style={styles.loginBox}>
  82. <View style={styles.loginContainer}>
  83. <View style={{padding:5}}>
  84. <SvgUri width="200" height="200" source={require('../Image/user.svg')} />
  85. </View>
  86. <View style={styles.wrapperStyle}>
  87. <Label text="USER NAME" />
  88. <TextInput
  89. style={styles.textInput}
  90. underlineColorAndroid='transparent'
  91. onChangeText={ (username => this.setState({username})) }
  92. placeholder="Laura wilson"
  93. placeholderTextColor="#FFFFFF"
  94. />
  95. </View>
  96. </View>
  97. <View style={styles.loginContainer}>
  98. <View style={{padding:5}}>
  99. <SvgUri width="200" height="200" source={require('../Image/password.svg')} />
  100. </View>
  101. <View style={styles.wrapperStyle}>
  102. <Label text="PASSWORD" />
  103. <TextInput
  104. style={styles.textInput}
  105. underlineColorAndroid='transparent'
  106. onChangeText={ (user_pass => this.setState({user_pass})) }
  107. placeholder="********"
  108. placeholderTextColor="#FFFFFF"
  109. />
  110. </View>
  111. </View>
  112. <View style={styles.loginContainer}>
  113. <View style={{padding:5}}>
  114. <SvgUri width="200" height="200" source={require('../Image/email.svg')} />
  115. </View>
  116. <View style={styles.wrapperStyle}>
  117. <Label text="EMAIL" />
  118. <TextInput
  119. style={styles.textInput}
  120. underlineColorAndroid='transparent'
  121. onChangeText={ (email => this.setState({email})) }
  122. placeholder="Laura wilson"
  123. placeholderTextColor="#FFFFFF"
  124. />
  125. </View>
  126. </View>
  127. <View style={styles.loginContainer}>
  128. <View style={{padding:5}}>
  129. <SvgUri width="200" height="200" source={require('../Image/mobile.svg')} />
  130. </View>
  131. <View style={styles.wrapperStyle}>
  132. <Label text="PHONE NUMBER" />
  133. <TextInput
  134. secureTextEntry={true}
  135. style={styles.textInput}
  136. underlineColorAndroid='transparent'
  137. onChangeText={ (contact => this.setState({contact})) }
  138. placeholder="+123 456 789"
  139. placeholderTextColor="#FFFFFF"
  140. />
  141. </View>
  142.  
  143. </View>
  144. <TouchableOpacity
  145. style={styles.buttonStyle} onPress={() => this.registerUser()}
  146. >
  147. <Text style={styles.textStyle}>Signup</Text>
  148. </TouchableOpacity>
  149. <Text style={{color: 'rgba(255, 255, 255, 0.6)',fontSize: 12, textAlign: 'center',paddingTop:10}}>
  150. Already Member?
  151. </Text>
  152. <Text style={{color: 'white', fontWeight: 'bold', marginTop: 5, textAlign: 'center'}}
  153. onPress={() => navigate('Login')}>
  154. Login
  155. </Text>
  156. </View>
  157. </View>
  158. </ScrollView>
  159. );
  160. }
  161. }
  162.  
  163. const styles = StyleSheet.create({
  164. main:{
  165. flex:1,
  166. backgroundColor: '#0050A1',
  167. },
  168. box:{
  169. flex:1,
  170. alignItems:'center',
  171. justifyContent:'center',
  172. alignSelf:'center'
  173. },
  174. ImageStyle: {
  175. padding: 10,
  176. margin: 5,
  177. height: 25,
  178. width: 25,
  179. resizeMode : 'stretch',
  180. },
  181. label: {
  182. color: '#fff',
  183. fontSize: 20
  184. },
  185. imageStyle: {
  186. marginTop: 5,
  187. height: 66,
  188. width: 200
  189. },
  190. container: {
  191. margin: 10,
  192. marginLeft: 0,
  193. alignContent:'center',
  194. marginBottom: 50,
  195. padding: 20
  196. },
  197. headerStyle: {
  198. flexDirection: 'row',
  199. flex: -1,
  200. marginRight: 20
  201. },
  202. firstHeaderStyle: {
  203. flexDirection: 'row',
  204. flex: -1,
  205. marginTop: 75,
  206. marginRight: 20
  207. },
  208. buttonStyle:{
  209. alignSelf: 'stretch',
  210. borderRadius: 27,
  211. borderWidth: 1,
  212. margin:25,
  213. borderColor: '#0086e5',
  214. backgroundColor:'#0086e5',
  215. padding:10,
  216. },
  217. textStyle:{
  218. color: 'white',
  219. fontSize: 18,
  220. textAlign:'center',
  221. fontWeight: 'bold',
  222. },
  223. textInput: {
  224. height: 40,
  225. fontSize: 18,
  226. color:'rgba(255, 255, 255, 0.6)',
  227. width: '100%',
  228. fontFamily: 'system',
  229. borderBottomWidth:0.8,
  230. borderBottomColor:'#fff'
  231. },
  232. overlay: {
  233. width: '100%',
  234. height: '100%',
  235. backgroundColor: 'rgba(0, 80, 161, 0.8)',
  236. position: 'absolute',
  237. top: 0,
  238. left: 0,
  239. zIndex: 999,
  240. justifyContent: 'space-around'
  241. },
  242. //added styles
  243.  
  244. loginBox:{
  245. flex:0.7,
  246. alignItems:'center',
  247. justifyContent:'center',
  248. alignSelf:'center',
  249. margin:10,
  250. },
  251. loginContainer:{
  252. flexDirection: 'row',
  253. flex:1,
  254. justifyContent:'center',
  255. alignItems:'center',
  256. marginTop:0,
  257. marginBottom:5,
  258. paddingTop:5,
  259. paddingBottom:5
  260. },
  261. wrapperStyle:{
  262. flexDirection: 'column',
  263. flex:3,
  264. justifyContent:'center',
  265. paddingLeft:5,
  266. paddingBottom:5,
  267. marginTop:5,
  268. marginBottom:5,
  269. }
  270. });
Add Comment
Please, Sign In to add comment