Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable} from '@angular/core';
- import {Http, Headers} from '@angular/http';
- //on veut que notre post soit observable on va donc utiliser rxjs
- import 'rxjs/add/operator/map';
- import map = require("core-js/fn/array/map");
- @Injectable()
- export class RegisterService{
- public isNewUser: boolean;
- constructor(private http:Http){
- }
- //prout methode pour ajouter les user rempli dans le formulaire vers la DB
- addUser(email,pseudo,password,picture,contactList){
- console.log(JSON.stringify(email));
- console.log(JSON.stringify(pseudo));
- console.log(JSON.stringify(picture));
- let newUser={
- email : email,
- pseudo : pseudo,
- picture : picture,
- password : password,
- contactList : contactList
- }
- console.log(JSON.stringify(newUser));
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- return this.http.post('http://localhost:3000/api/user', JSON.stringify(newUser), {headers}).subscribe(//JSON.stringify(newUser)
- data => {
- console.log(data.json());
- }
- );
- }
- isNew(pseudo){
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- //console.log("je suis dans le register service dans isNew et mon pseudo est :"+pseudo);
- if(this.isNewUser == undefined){
- return this.http.post('http://localhost:3000/api/isNewUser/'+pseudo,{headers})
- .map(isNew => {
- this.isNewUser = isNew.json();
- //console.log(this.isNewUser);
- return this.isNewUser;
- }).toPromise();
- }
- }
- /*
- addPicture(picture){
- console.log('yoooooooooooooooooolo')
- console.log(picture)
- console.log(picture.name)
- //console.log(picture.json())
- let myPicture={
- name : picture.name,
- size : picture.size,
- path : picture.webkitRelativePath,
- type : picture.type
- }
- console.log(JSON.stringify(myPicture));
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- return this.http.post('http://localhost:3000/api/pictureUser', JSON.stringify(myPicture), {headers}).subscribe(
- data => {
- console.log('hduasc0ipdosnvpidsnv oifdnb lifdanv f;klednv fd;kls')
- return data.json()
- }, err=> {
- console.log(err);
- }
- );
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement