Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import {Injectable} from '@angular/core';
  2. import {Http, Headers} from '@angular/http';
  3. //on veut que notre post soit observable on va donc utiliser rxjs
  4. import 'rxjs/add/operator/map';
  5. import map = require("core-js/fn/array/map");
  6.  
  7.  
  8. @Injectable()
  9. export class RegisterService{
  10. public isNewUser: boolean;
  11.  
  12. constructor(private http:Http){
  13.  
  14. }
  15.  
  16. //prout methode pour ajouter les user rempli dans le formulaire vers la DB
  17. addUser(email,pseudo,password,picture,contactList){
  18. console.log(JSON.stringify(email));
  19. console.log(JSON.stringify(pseudo));
  20. console.log(JSON.stringify(picture));
  21. let newUser={
  22. email : email,
  23. pseudo : pseudo,
  24. picture : picture,
  25. password : password,
  26. contactList : contactList
  27. }
  28.  
  29. console.log(JSON.stringify(newUser));
  30.  
  31.  
  32. var headers = new Headers();
  33. headers.append('Content-Type', 'application/json');
  34. return this.http.post('http://localhost:3000/api/user', JSON.stringify(newUser), {headers}).subscribe(//JSON.stringify(newUser)
  35. data => {
  36. console.log(data.json());
  37. }
  38. );
  39.  
  40. }
  41.  
  42. isNew(pseudo){
  43.  
  44. var headers = new Headers();
  45. headers.append('Content-Type', 'application/json');
  46. //console.log("je suis dans le register service dans isNew et mon pseudo est :"+pseudo);
  47. if(this.isNewUser == undefined){
  48. return this.http.post('http://localhost:3000/api/isNewUser/'+pseudo,{headers})
  49. .map(isNew => {
  50. this.isNewUser = isNew.json();
  51. //console.log(this.isNewUser);
  52. return this.isNewUser;
  53. }).toPromise();
  54. }
  55. }
  56. /*
  57. addPicture(picture){
  58. console.log('yoooooooooooooooooolo')
  59. console.log(picture)
  60. console.log(picture.name)
  61.  
  62. //console.log(picture.json())
  63. let myPicture={
  64. name : picture.name,
  65. size : picture.size,
  66. path : picture.webkitRelativePath,
  67. type : picture.type
  68.  
  69. }
  70. console.log(JSON.stringify(myPicture));
  71.  
  72. var headers = new Headers();
  73. headers.append('Content-Type', 'application/json');
  74. return this.http.post('http://localhost:3000/api/pictureUser', JSON.stringify(myPicture), {headers}).subscribe(
  75. data => {
  76. console.log('hduasc0ipdosnvpidsnv oifdnb lifdanv f;klednv fd;kls')
  77. return data.json()
  78. }, err=> {
  79. console.log(err);
  80. }
  81. );
  82. }*/
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement