Advertisement
Guest User

Untitled

a guest
Feb 18th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. fetch('http://localhost:3000/user/addUser', {
  2. method: 'post',
  3. headers: {
  4. 'Content-Type': 'application/json'
  5. },
  6. body: JSON.stringify({
  7. firstname: user.firstname,
  8. lastname: user.lastname,
  9. email: user.email,
  10. password: user.password,
  11. avatar: user.avatar
  12. })
  13. })
  14. .then((data) => {
  15. // TO DO : Manage pending HTTP request in the store
  16. console.log('Subscribe done');
  17. browserHistory.push('/');
  18.  
  19. fetch('http://localhost:3000/user/', {
  20. method: 'GET',
  21. params: {
  22. email: user.email
  23. }
  24. })
  25. .then((resp) => resp.json())
  26. .then((data) => {
  27. user.FIRSTNAME = data.FIRSTNAME ? data.FIRSTNAME : '';
  28. user.LASTNAME = data.LASTNAME ? data.LASTNAME : '';
  29. user.EMAIL = data.EMAIL ? data.EMAIL : '';
  30. user.CITY = data.CITY ? data.CITY : '';
  31. user.RANKING = data.RANKING ? data.RANKING : '';
  32. user.AVATAR = data.AVATAR ? data.AVATAR : '';
  33. if (user) {
  34. const initData = {
  35. 'firstname': user.FIRSTNAME.toString(),
  36. 'lastname': user.LASTNAME.toString(),
  37. 'city': user.CITY.toString(),
  38. 'email': user.EMAIL.toString(),
  39. 'ranking': user.RANKING.toString(),
  40. 'avatar': user.AVATAR.toString()
  41. };
  42. this.props.initialize(initData);
  43. }
  44. })
  45. .catch((error) => {
  46. console.log('Subscribe error');
  47. console.log(error);
  48. });
  49.  
  50. return Object.assign({}, state, {
  51. user: {
  52. id: 1,
  53. firstname: user.firstname,
  54. lastname: user.lastname,
  55. avatar: user.avatar
  56. }
  57. });
  58. })
  59. .catch((error) => {
  60. console.log(error);
  61. return state;
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement