Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import {Storage, LocalStorage} from 'ionic-angular';
  2.  
  3. import {Inject} from 'angular2/core';
  4. import {Http} from 'angular2/http';
  5. import 'rxjs/add/operator/map';
  6.  
  7. export class DAOLogin {
  8.  
  9. static get parameters() {
  10. return [[Http]];
  11. }
  12.  
  13. constructor(http) {
  14. this.http = http;
  15.  
  16.  
  17. // var url = 'http://api.themoviedb.org/3/search/movie?query=&query=' + encodeURI('titanic') + '&api_key=5fbddf6b517048e25bc3ac1bbeafb919';
  18. // this.http.get(url).map(res => res.json());
  19.  
  20. }
  21.  
  22.  
  23.  
  24. login(obj) {
  25.  
  26. var username = obj.username;
  27. var password = obj.password;
  28.  
  29. var creds = "username=" + username + "&password=" + password;
  30.  
  31. var headers = new Headers();
  32. headers.append('Content-Type', 'application/x-www-form-urlencoded');
  33.  
  34. this.http.post('http://localhost:3001/sessions/create', creds, {
  35. headers: headers
  36. })
  37. .map(res => res.json())
  38. .subscribe(
  39. data => this.saveJwt(data.id_token),
  40. err => this.logError(err),
  41. () => console.log('Authentication Complete')
  42. );
  43.  
  44. // var body = "username=" + obj.username + "&password=" + obj.password;
  45. // var headers = new Headers();
  46. // headers.append('Content-Type', 'application/x-www-form-urlencoded');
  47.  
  48. // this.http
  49. // .post('http://localhost:3001/sessions/create',
  50. // body, {
  51. // headers: headers
  52. // })
  53. // .map(response => response.json())
  54. // .subscribe(
  55. // response => this.storeToken(response.id_token),
  56. // this.logError,
  57. // () => console.log('Authentication Complete')
  58. // );
  59.  
  60. }
  61.  
  62. // login(obj) {
  63. // console.log('entrou - username: '+obj.username+', password:'+obj.password);
  64. // }
  65.  
  66. // setTokenLocalStorage(token) {
  67. // this.local = new Storage(LocalStorage);
  68. // this.local.get('token').then((result) => {
  69. // if(!result){
  70. // this.local.set('token', token);
  71. // console.log('token criado em local storage: token => '+ token);
  72. // }
  73. // });
  74. // }
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement