Created
August 23, 2016 17:01
-
-
Save binzailani3136/c6baafdee89d2f536365a0324d8cd4b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Fetch = require('whatwg-fetch'); | |
var baseUrl = 'https://secure.budgettracker.com/api/'; | |
var service = { | |
get: function(url){ | |
return fetch(baseUrl+url) | |
.then(function(response) { | |
return response.json() | |
}); | |
}, | |
post: function(url,params){ | |
var uri = baseUrl+url; | |
console.log('URI=========',uri); | |
console.log(params); | |
return fetch(uri, { | |
headers: { | |
'Accept': 'text/plain', | |
'Content-Type': 'application/json' | |
}, | |
method:'post', | |
body:JSON.stringify(params) | |
}).then(function(response) { | |
return response.json() | |
}); | |
}, | |
}; | |
module.exports = service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var HTTP = require('../services/httpservice'); | |
var Reflux = require('reflux'); | |
var Actions = require('./actions.jsx.js'); | |
var LoginStore = Reflux.createStore({ | |
listenables: [Actions], | |
loginUser: function(values){ | |
HTTP.post('api_login.php',values) | |
.then(function(json){ | |
this.fireUpdate(json.status); | |
}.bind(this)); | |
}, | |
fireUpdate: function(status){ | |
this.trigger('login'+status) | |
} | |
}); | |
module.exports = LoginStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import React, { Component } from 'react'; | |
import { Form, InputField, | |
Separator, SwitchField, LinkField , | |
PickerField, DatePickerField | |
} from 'react-native-form-generator'; | |
var Button = require('react-native-button'); | |
var Actions = require('../reflux/actions.jsx.js'); | |
var Reflux = require('reflux'); | |
var LoginStore = require('../reflux/login-store.jsx.js'); | |
import { | |
StyleSheet, | |
Text, | |
TextInput, | |
Modal, | |
View, | |
TouchableOpacity, | |
Image | |
} from 'react-native'; | |
var Login = React.createClass ({ | |
mixins: [Reflux.listenTo(LoginStore,'onChange')], | |
getInitialState: function() { | |
return { | |
formData:{} | |
} | |
}, | |
onChange: function(event){ | |
console.log(event); | |
if(event == 'loginsuccess') { | |
this.props.navigator.popToTop(0); | |
} | |
else if(event == 'loginfailed') { | |
this.setState({formData: {}}); | |
} | |
}, | |
handleFormFocus: function(){ | |
}, | |
handleFormChange: function(formData){ | |
this.setState({formData: formData}); | |
}, | |
login: function(){ | |
console.log(this.state.formData); | |
Actions.loginUser(this.state.formData); | |
}, | |
render: function(){ | |
return ( | |
<View style={styles.container}> | |
<Form | |
ref='registrationForm' | |
onFocus={this.handleFormFocus} | |
onChange={this.handleFormChange} | |
label="Personal Information"> | |
<InputField ref='emailaddress' label='Email' value={this.state.formData.emailaddress} placeholder='Email'/> | |
<InputField secureTextEntry={true} value={this.state.formData.password} ref='password' label='Password' placeholder='Password'/> | |
<Button onPress={ () => this.login() }>Login</Button> | |
</Form> | |
</View> | |
) | |
} | |
}); | |
var styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
marginTop:84, | |
}, | |
textEdit: { | |
height: 40, | |
borderColor: '#EEE', | |
backgroundColor: 'white', | |
borderWidth: 1 | |
}, | |
buttonContainer: { | |
marginTop:20, | |
height: 80, | |
backgroundColor: 'red' | |
}, | |
button: { | |
padding: 20 | |
} | |
}); | |
module.exports = Login; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment