Guest User

Untitled

a guest
Jan 3rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. TextInput, Button
  8. } from 'react-native';
  9.  
  10. export default class LoginForm extends Component<{}> {
  11. constructor(props) {
  12. super(props);
  13. this._onLogInPressed = this._onLogInPressed.bind(this);
  14. this._response_recognizer = this._response_recognizer.bind(this);
  15. this.state = {
  16. phone_number: '',
  17. password: '',
  18. data: {}
  19. };
  20. }
  21. _response_recognizer(data: string ){
  22.  
  23. }
  24.  
  25. _onLogInPressed = () => {
  26.  
  27. var data = {
  28. 'phone_number': this.state.phone_number,
  29. 'password': this.state.password
  30. }
  31.  
  32.  
  33. fetch("http://192.168.1.12:5000/login", {
  34. method: "POST",
  35. headers: {
  36. 'Accept': 'application/json',
  37. 'Content-Type': 'application/json',
  38. },
  39. body: JSON.stringify(data)
  40. }).then(function(response){
  41. return response.json();
  42. }).then(function(data){
  43. console.log(data)
  44. this._response_recognizer(data)
  45. }) .catch((error) => {
  46. console.log("Error" + error);
  47. });
  48. };
  49.  
  50. render() {
  51. return (
  52. <View style={styles.flow}>
  53. <Text style={styles.text}>phone number:</Text>
  54. <TextInput keyboardType='numeric'
  55. style={styles.input}
  56. ref="phone_number"
  57. onChangeText={(phone_number) => this.setState({phone_number})}
  58. maxLengt={11}
  59. value={this.state.phone_number}
  60. />
  61. <Text style={styles.text}>password:</Text>
  62. <TextInput style={styles.input} secureTextEntry={true} ref="password"
  63. onChangeText={(password) => this.setState({password})}
  64. value={this.state.password}/>
  65. <Button style={styles.button} onPress={this._onLogInPressed} title='login'/>
  66. </View>
  67. );
  68. }
  69. }
Add Comment
Please, Sign In to add comment