Advertisement
Guest User

Untitled

a guest
Nov 29th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StyleSheet, Text, View, Image,KeyboardAvoidingView,TouchableOpacity, AsyncStorage, Keyboard } from 'react-native';
  3. import { Container, Header, Tab, Tabs, StyleProvider, TabHeading, Icon, Form, Item, Label, Input, Button,Toast } from 'native-base';
  4.  
  5.  
  6. import getTheme from '../native-base-theme/components';
  7. import material from '../native-base-theme/variables/material';
  8.  
  9. export default class Login extends Component {
  10.  
  11.  
  12. constructor(props) {
  13. super(props);
  14.  
  15. this.state = {
  16. username:'',
  17. showToast: false,
  18. password:''
  19.  
  20. };
  21. }
  22.  
  23. componentDidMount(){
  24. this._loadInitialState().done();
  25. }
  26.  
  27. _loadInitialState = async () => {
  28. var value = await AsyncStorage.getItem('userid');
  29.  
  30. if(value !== null){
  31. this.props.navigation.navigate('Dashboard')
  32. }
  33. }
  34.  
  35. static navigationOptions = { header: null }
  36. render() {
  37.  
  38. var {navigate} = this.props.navigation;
  39. return (
  40.  
  41. <StyleProvider style={getTheme(material)}>
  42. <KeyboardAvoidingView behavior="padding" style={styles.container}>
  43. <View style={styles.slider}>
  44. <Image style={styles.images} source={require('../img/newbg.png')} />
  45. </View>
  46. <View style={styles.getstarted}>
  47.  
  48. <Form>
  49. <Item>
  50. <Input
  51. returnKeyType="next"
  52. keyboardType="email-address"
  53. autoCapitalize="none"
  54. autoCorrect={false}
  55. onChangeText= {username => this.setState({username })}
  56. placeholder="Email or Username" />
  57. </Item>
  58. <Item last>
  59. <Input
  60. secureTextEntry
  61. returnKeyType="go"
  62.  
  63. onChangeText= {password => this.setState({password })}
  64. placeholder="Password" />
  65. </Item>
  66.  
  67. <View style={styles.wrapbut}>
  68.  
  69. <Button block onPress={this.login} >
  70. <Text style={styles.butcolor}>LOGIN</Text>
  71. </Button>
  72. <Button transparent style={styles.forgbut}>
  73. <Text style={styles.forgot}>FORGOT PASSWORD ?</Text>
  74. </Button>
  75. <Button block success onPress={() => navigate("Register")}>
  76. <Text style={styles.butcolor}>CREATE NEW DOOKITA ACCOUNT</Text>
  77. </Button>
  78. </View>
  79. </Form>
  80.  
  81.  
  82. </View>
  83. </KeyboardAvoidingView>
  84. </StyleProvider>
  85. );
  86. }
  87.  
  88. login =() =>{
  89.  
  90. Keyboard.dismiss();
  91.  
  92. fetch('http://native.codefest.com.ng/api/postlogin',{
  93. method: 'post',
  94. headers:{
  95. 'Accepts': 'application/json',
  96. 'Content-Type':'application/json',
  97. },
  98. body: JSON.stringify({
  99. username: this.state.username,
  100. password: this.state.password,
  101. throttle: 'Patients'
  102. })
  103. })
  104.  
  105. .then((response)=> response.json())
  106. .then((res)=>{
  107.  
  108.  
  109. if(res.status === true){
  110.  
  111. let myarray={
  112. id: res.logintoken,
  113. fname: res.fname,
  114. lname: res.lname
  115. }
  116. AsyncStorage.setItem('userid', JSON.stringify(myarray));
  117. this.props.navigation.navigate('Dashboard');
  118. }else{
  119.  
  120. Toast.show({
  121. text: res.status,
  122. position: 'bottom',
  123. buttonText: 'Okay'
  124. });
  125. }
  126.  
  127.  
  128. }).done();
  129.  
  130.  
  131. }
  132. }
  133.  
  134.  
  135. const styles = StyleSheet.create({
  136. container: {
  137. flex: 1,
  138. },
  139. slider:{
  140. flex: 2,
  141. },
  142. getstarted:{
  143. flex:3,
  144. backgroundColor: '#fff',
  145. paddingTop: 25,
  146. paddingHorizontal: 25,
  147.  
  148.  
  149.  
  150. },
  151. images:{
  152. alignItems:'center',
  153. justifyContent: 'center',
  154. height: null,
  155. width: null,
  156. flexGrow: 1,
  157.  
  158. },
  159. butcolor:{
  160. color: '#fff',
  161. fontSize: 13,
  162. },
  163. forgot:{
  164. color: '#1464c0',
  165. fontSize: 12,
  166. fontWeight: '500',
  167. },
  168. forgbut:{
  169. alignSelf: 'center',
  170.  
  171. },
  172. wrapbut:{
  173. marginTop: 25,
  174. }
  175. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement