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");
- import {User} from "../../../User";
- @Injectable()
- export class RegisterService{
- public isNewUser: boolean;
- public userGet: User;
- constructor(private http:Http){
- }
- //prout methode pour ajouter les user rempli dans le formulaire vers la DB
- addUser(email,pseudo,password,picture,secret,contactList,contactInvites,birthday){
- 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,
- contactInvitesList : contactInvites,
- bio:'',
- birthday:birthday,
- exist:true,
- secret:secret
- }
- 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(
- data => {
- console.log(data.json());
- }
- );
- }
- /*
- isExist(pseudo){
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- if(this.isNewUser == undefined){
- return this.http.post('http://localhost:3000/api/isNewUser/'+pseudo,{headers})
- .map(isExist => {
- this.isUserExist = isExist.json();
- //console.log(this.isNewUser);
- return this.isNewUser;
- }).toPromise();
- }
- }*/
- getUserByPseudo(userByPseudo){
- console.log("getUserByPseudo lllll")
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- return this.http.post('http://localhost:3000/login/getUserByPseudo',JSON.stringify(userByPseudo),{headers})
- .map(userGet => {
- this.userGet = userGet.json();
- console.log("profil service userGet par le pseudo : " + this.userGet.pseudo);
- return this.userGet;
- }).toPromise();
- }
- getUserByEmail(userByEmail){
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- return this.http.post('http://localhost:3000/login/getUserByEmail',JSON.stringify(userByEmail),{headers})
- .map(userGet => {
- this.userGet = userGet.json();
- console.log("profil service userGet : " + this.userGet.pseudo);
- return this.userGet;
- }).toPromise();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement