Advertisement
enkf

Untitled

Jan 23rd, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Text, View, StyleSheet, TouchableOpacity, TextInput} from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button } from 'native-base';
  5. import { withNavigation } from 'react-navigation';
  6. import Axios from 'axios';
  7.  
  8.  
  9. class Login extends Component{
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. email: '',
  14. password: '',
  15. }
  16. }
  17.  
  18. // componentDidMount() {
  19. // Axios({
  20. // method: 'get',
  21. // url: 'http://192.168.56.1/vzuu/public/api/user',
  22. // dataType: 'json',
  23. // headers: {
  24. // 'Accept': 'application/json',
  25. // 'Content-Type': 'application/json'
  26. // },
  27. // })
  28. // .then(function(response) {
  29. // console.log(response);
  30. // })
  31. // .catch(function(error) {
  32. // console.log(error);
  33. // })
  34. // }
  35.  
  36. handleSubmit = () => {
  37. console.log(this.state);
  38. Axios({
  39. method: 'post',
  40. url: 'http://192.168.56.1/vzuu/public/api/login',
  41. dataType: 'json',
  42. headers: {
  43. 'Accept': 'application/json',
  44. 'Content-Type': 'application/json',
  45. },
  46. data: {
  47. email: this.state.email,
  48. password: this.state.password,
  49. },
  50. })
  51. .then((response) => {
  52. console.log(response.data);
  53. AsyncStorage.setItem('token', response.data.token);
  54. this.props.navigation.navigate('Home');
  55. })
  56. .catch(function(error) {
  57. console.log(error);
  58. });
  59. this.setState({email: '', password:'',});
  60. }
  61.  
  62. render() {
  63. return(
  64. <View style={styles.container}>
  65. <View style={styles.mar}>
  66. <Text style={styles.txtlog}>Silahkan Login</Text>
  67. </View>
  68. <TextInput style={styles.text} onChangeText={email => this.setState({ email})} value={this.state.email} placeholder="Email" underlineColorAndroid="#E91E63" />
  69. <TextInput style={styles.text} secureTextEntry={true} onChangeText={password => this.setState({ password })} value={this.state.password} placeholder="Password" underlineColorAndroid="#E91E63"/>
  70. <Button rounded primary style={styles.buttonText} onPress={this.handleSubmit}>
  71. <Text style={styles.txt}>Login</Text>
  72. </Button>
  73. </View>
  74.  
  75. )
  76. }
  77. }
  78.  
  79. export default withNavigation(Login);
  80. const styles = StyleSheet.create({
  81. container: { flex: 1, justifyContent: 'center', alignItems: 'center'},
  82. text: {fontSize: 16, width: 280 },
  83. buttonText: { fontSize: 16, color: '#ffffff', marginTop: 15},
  84. txt: { color: '#fff', fontSize: 16, width: 280, textAlign: 'center'},
  85. imgBackground : { width: '100%', height: '100%' },
  86. txtlog: { fontSize: 18, textAlign: 'center', marginTop: 100 },
  87. mar: { marginTop: 30 }
  88.  
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement