Guest User

Untitled

a guest
Oct 18th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Http } from '@angular/http';
  3. import 'rxjs/add/operator/map';
  4.  
  5. import { URL_SERVICES } from '../../config/url.services';
  6.  
  7. import { AlertController } from 'ionic-angular';
  8.  
  9. @Injectable()
  10. export class UsersProvider {
  11.  
  12. token:string;
  13. id_user:string;
  14.  
  15. constructor(public http: Http,
  16. private alertCtrl: AlertController) {
  17. console.log('Hello UsersProvider Provider');
  18. }
  19.  
  20. ingresar( email:string, password:string){
  21. console.log("usersP ",email);
  22. console.log("usersP ", password);
  23.  
  24. let data = new URLSearchParams();
  25. data.append("email", email);
  26. data.append("password", password);
  27.  
  28. let url = URL_SERVICES + "login";
  29.  
  30. return this.http.post( url, data )
  31. .map( resp => {
  32.  
  33. let data_resp = resp.json();
  34. console.log( data_resp );
  35.  
  36. if( data_resp.err ){
  37. this.alertCtrl.create({
  38. title: 'Error al iniciar',
  39. subTitle: data_resp.message,
  40. buttons: ['OK']
  41. }).present();
  42.  
  43. }else{
  44. this.token = data_resp.token;
  45. this.id_user = data_resp.id_user;
  46.  
  47. //GUARDAR STORAGE
  48. }
  49.  
  50. });
  51.  
  52. }
  53.  
  54. }
Add Comment
Please, Sign In to add comment