Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StyleSheet, Text, TextInput, TouchableOpacity } from 'react-native';
  3. import { Container, View, Item, Input } from 'native-base';
  4. import axios from 'axios';
  5.  
  6. class Login extends Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. email: '',
  11. password: '',
  12. }
  13. }
  14.  
  15.  
  16. componentDidMount() {
  17. axios({
  18. method: 'get',
  19. url: 'http://192.168.56.1/lrn/public/api/user',
  20. dateType: 'json',
  21. headers: {
  22. 'Accept': 'application/json',
  23. 'Content-Type': 'application/json',
  24. },
  25. })
  26. .then(function (response) {
  27. console.log(response);
  28. })
  29. .catch(function (error) {
  30. console.log(error);
  31. })
  32. }
  33.  
  34. handleSubmit = () => {
  35. axios({
  36. method: 'post',
  37. url: 'http://192.168.56.1/lrn/public/api/login',
  38. dataType: 'json',
  39. headers: {
  40. 'Accept': 'application/json',
  41. 'Content-Type': 'application/json',
  42. },
  43. data: {
  44. email: this.state.email,
  45. password: this.state.password,
  46. },
  47. })
  48. .then(function (response) {
  49. console.log(response.data);
  50. })
  51. .catch(function (error) {
  52. console.log(error);
  53. });
  54. this.setState({ email: '', password: '', });
  55. }
  56.  
  57. render() {
  58. return (
  59. <Container>
  60. <View style={styles.down}>
  61.  
  62. <TextInput placeholder="Email" onChangeText={email => this.setState({ email })} value={this.state.email} underlineColorAndroid='#1171EC' />
  63. </View>
  64. <View style={styles.container}>
  65. </View>
  66. <TextInput placeholder="Password" secureTextEntry={true} onChangeText={password => this.setState({ password })} value={this.state.password} underlineColorAndroid='#1171EC' />
  67. <View style={styles.container}>
  68. </View>
  69. <TouchableOpacity onPress={this.handleSubmit} style={styles.button} >
  70. <Text style={styles.buttonText}>Login</Text>
  71. </TouchableOpacity>
  72. </Container>
  73. )
  74. }
  75. }
  76. export default Login;
  77. const styles = StyleSheet.create({
  78. container: {
  79. justifyContent: 'center',
  80. alignItems: 'center',
  81. },
  82. inputBox: {
  83. width: 300,
  84. backgroundColor: 'transparent',
  85. borderRadius: 25,
  86. paddingHorizontal: 16,
  87. fontSize: 16,
  88. color: '#000',
  89.  
  90. },
  91. button: {
  92. width: 280,
  93. backgroundColor: '#32CD32',
  94. borderRadius: 25,
  95. marginVertical: 10,
  96. paddingVertical: 12
  97. },
  98. buttonText: {
  99. fontSize: 16,
  100. fontWeight: '500',
  101. color: '#fff',
  102. textAlign: 'center'
  103. },
  104. borderStyle: 25
  105. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement