Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. export default class Form extends Component<{}> {
  2. constructor(){
  3. super();
  4. this.state={
  5. username:'',
  6. password:''
  7. }
  8. }
  9. updateValue(text,field){
  10. if(field=='username'){
  11. this.setState({
  12. username:text,
  13. })
  14. }else if(field=='password'){
  15. this.setState({
  16. password:text,
  17. })
  18. }
  19. }
  20. _onLoginButton() {
  21. let collection = {}
  22. collection.username = this.state.username,
  23. collection.password = this.state.password
  24. console.warn(collection)
  25.  
  26.  
  27. var url = 'http://10.10.10.128:3000/api/auth/login';
  28.  
  29. fetch(url, {
  30. method: 'POST',
  31. body: JSON.stringify(collection),
  32. headers:{
  33. 'Content-Type': 'application/json'
  34. }
  35. }).then((response) => response.json())
  36. .then((responseJson) => {
  37. () =>navigate('FormHome')
  38. })
  39. .catch((error) => {
  40. console.error(error);
  41. });
  42.  
  43.  
  44. }
  45.  
  46. //UI
  47. render(){
  48. //console.warn("navigate = " + until.inspect(this.props.navigation, false, null));
  49. const { navigate } = this.props.navigation;
  50.  
  51. return(
  52. // <KeyboardAvoidingView behavior="padding">
  53. <View style={styles.container}>
  54. <StatusBar
  55. backgroundColor="#00c1c8"
  56. barStyle="light-content"
  57. />
  58. <Logo/>
  59. <TextInput style={styles.inputBox}
  60. underlineColorAndroid='rgba(0,0,0,0)'
  61. placeholder="Email"
  62. placeholderTextColor = "#e1dddd"
  63. selectionColor="#fff"
  64. keyboardType="email-address"
  65. onSubmitEditing={()=> this.password.focus()}
  66. onChangeText= {(text)=>this.updateValue(text, 'username')}
  67. />
  68.  
  69. <TextInput style={styles.inputBox}
  70. underlineColorAndroid='rgba(0,0,0,0)'
  71. placeholder="Password"
  72. secureTextEntry={true}
  73. placeholderTextColor = "#e1dddd"
  74. ref={(input) => this.password = input}
  75. onChangeText= {(text)=>this.updateValue(text, 'password')}
  76.  
  77. />
  78. <TouchableOpacity
  79. onPress={()=>this._onLoginButton()}
  80. style={styles.button}>
  81. <Text style={styles.buttonText}>Login </Text>
  82. </TouchableOpacity>
  83.  
  84. <Text style={styles.signupText}>OR</Text>
  85. <TouchableOpacity
  86. onPress={
  87. () =>navigate('FormSignup')
  88. }>
  89. <Text style={styles.signupButton}> Signup</Text>
  90. </TouchableOpacity>
  91. </View>
  92. // </KeyboardAvoidingView>
  93.  
  94. )
  95.  
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement