Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 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. import {User} from "../../../User";
  7.  
  8.  
  9. @Injectable()
  10. export class RegisterService{
  11.  
  12. public isNewUser: boolean;
  13. public userGet: User;
  14. constructor(private http:Http){
  15.  
  16. }
  17.  
  18. //prout methode pour ajouter les user rempli dans le formulaire vers la DB
  19. addUser(email,pseudo,password,picture,secret,contactList,contactInvites,birthday){
  20. console.log(JSON.stringify(email));
  21. console.log(JSON.stringify(pseudo));
  22. console.log(JSON.stringify(picture));
  23.  
  24. let newUser={
  25. email : email,
  26. pseudo : pseudo,
  27. picture : picture,
  28. password : password,
  29. contactList : contactList,
  30. contactInvitesList : contactInvites,
  31. bio:'',
  32. birthday:birthday,
  33. exist:true,
  34. secret:secret
  35. }
  36.  
  37. console.log(JSON.stringify(newUser));
  38.  
  39.  
  40. var headers = new Headers();
  41. headers.append('Content-Type', 'application/json');
  42. return this.http.post('http://localhost:3000/api/user', JSON.stringify(newUser), {headers}).subscribe(
  43. data => {
  44. console.log(data.json());
  45. }
  46. );
  47.  
  48. }
  49. /*
  50. isExist(pseudo){
  51.  
  52. var headers = new Headers();
  53. headers.append('Content-Type', 'application/json');
  54. if(this.isNewUser == undefined){
  55. return this.http.post('http://localhost:3000/api/isNewUser/'+pseudo,{headers})
  56. .map(isExist => {
  57. this.isUserExist = isExist.json();
  58. //console.log(this.isNewUser);
  59. return this.isNewUser;
  60. }).toPromise();
  61. }
  62. }*/
  63.  
  64. getUserByPseudo(userByPseudo){
  65. console.log("getUserByPseudo lllll")
  66. var headers = new Headers();
  67. headers.append('Content-Type', 'application/json');
  68.  
  69. return this.http.post('http://localhost:3000/login/getUserByPseudo',JSON.stringify(userByPseudo),{headers})
  70. .map(userGet => {
  71. this.userGet = userGet.json();
  72. console.log("profil service userGet par le pseudo : " + this.userGet.pseudo);
  73. return this.userGet;
  74. }).toPromise();
  75.  
  76. }
  77.  
  78. getUserByEmail(userByEmail){
  79. var headers = new Headers();
  80. headers.append('Content-Type', 'application/json');
  81. return this.http.post('http://localhost:3000/login/getUserByEmail',JSON.stringify(userByEmail),{headers})
  82. .map(userGet => {
  83. this.userGet = userGet.json();
  84. console.log("profil service userGet : " + this.userGet.pseudo);
  85. return this.userGet;
  86. }).toPromise();
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement