Guest User

Untitled

a guest
Dec 26th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. async storeToken(accesstoken) {
  2. try {
  3. await AsyncStorage.setItem(AccessToken, accesstoken);
  4. } catch (error) {
  5. console.log('AsyncStorage error: ' + error.message);
  6. }
  7. }
  8. userRegister = () =>{
  9. const {username} = this.state;
  10. const {password} = this.state;
  11.  
  12. if(username=="" || password==""){
  13. alert("Please fill out all fields");
  14. }
  15. // else if (password!=cpassword) {
  16. // alert("Passwords do not match.");
  17. // }
  18. else{
  19. fetch('http://192.168.01.1/test/register.php', {
  20. method: 'post',
  21. header:{
  22. 'Accept': 'application/json',
  23. 'Content-type': 'application/json'
  24. },
  25. body:JSON.stringify({
  26. username: username,
  27. password: password,
  28.  
  29. })
  30. })
  31. .then((response) => response.json())
  32. .then((responseData) =>{
  33. // how to define accesstoken
  34. //this.storeToken('accessToken',JSON.stringify(results));
  35. //if using in this then same error
  36. this.storeToken('accesstoken',responseData.accesstoken)
  37. if(responseData == 'User Registered Successfully'){
  38. Alert.alert(
  39. 'Success',
  40. 'User Registered Successfully',
  41. [
  42. // {text:'ok', onPress: () => this.props.navigation.goBack() }
  43. ]
  44. );
  45. //this.props.navigation.goBack()
  46. }else{
  47. alert(responseJson);
  48. }
  49. })
  50. .catch((error)=>{
  51. console.log(error);
  52. });
  53. }
  54. }
Add Comment
Please, Sign In to add comment